KatInterview

Design a Distributed Calendar Aggregation Engine

System DesignModel answer
MediumModel answerSystem Designsystem-designmapreducedistributed-systems

Last updated

Architect a MapReduce-based system to process massive calendar datasets and identify mutual free time slots of length d across large organizations.

System Requirement

Design a distributed processing pipeline (such as MapReduce) to analyze historical and upcoming calendar events for millions of users. The goal is to compute all common available time windows of at least duration $d$ for given user cohorts (e.g., team calendars, project groups, or entire enterprise divisions).

Input Data Format

  1. User Busy Intervals: High-volume logs formatted as (user_id, start_timestamp, end_timestamp). Timestamps are standard UTC Unix epoch values. Intervals are half-open $[start, end)$.
  2. Cohort / Group Membership: A mapping dataset structured as (group_id, user_id). A single user may belong to multiple groups.

Key Objectives

  • Formulate a scalable multi-stage MapReduce workflow. Clearly specify Map keys/values, Partitioning strategies, Combiner applicability, and Reducer logic for each stage.
  • Define how time discretization and window partitioning (e.g., daily buckets vs. discrete slotting) are handled without introducing edge artifacts.
  • Provide clear mechanisms to eliminate data skew caused by massive "all-hands" groups (up to tens of thousands of members) or power users with thousands of events/groups.
  • Detail validation strategies to guarantee correctness and idempotency across batch executions.

Hints

Hint 1

Interval union is associative and commutative. Use map-side combiners to merge individual busy blocks before shuffling group data.

Hint 2

Avoid fixed-size grid discretization to prevent precision loss and inflated data volume. Use boundary-clipped continuous intervals alongside temporal buckets.

Hint 3

For massive groups (high fan-out key skew), apply salting (key split) with a k-way secondary merge step.