KatInterview

Windowed Aggregation Pipeline for Calendar Event Logs

System DesignModel answer
HardModel answerSystem Designbig-datasparkmapreduce

Last updated

Design a Spark/MapReduce pipeline that computes rolling 15-minute concurrent meeting counts and room utilization from a large-scale event log.

Scenario

Your company operates hundreds of offices worldwide, each containing dozens of bookable rooms. A centralized scheduling system emits a log entry every time a user joins a meeting. Each record has the shape:

{ user_id, room_id, office_id, start_time, end_time }

Because the log is attendee-level, a ten-person meeting produces ten rows. The log accumulates roughly 500 million records per day and must support backfill over historical months.

What you need to build

Design a Spark (or MapReduce) job that reads this raw log and produces two outputs for every rolling 15-minute window (15-minute length, 5-minute step, UTC-aligned):

  1. Office concurrency — the peak number of simultaneously active meetings inside each office during the window.
  2. Overloaded rooms — every room whose utilization exceeds 80% in the window. Utilization is occupied_seconds / 900; double-booked or multi-attendee rows must not inflate it above 100%.

What the answer should cover

  • How you clean, deduplicate, and collapse attendee rows into distinct meetings.
  • The interval-transformation strategy you use to make windowed aggregation efficient (e.g., delta encoding, interval splitting, or another approach) — and why.
  • Map keys and values, shuffle/partition strategy, and how you avoid or handle skew from large offices.
  • How you handle late-arriving and duplicate events in both a batch and an optional streaming path.
  • At least three concrete validation checks you would run at scale before trusting the output.

There is no coding judge. Walk through your design as you would in a technical interview, covering correctness, scalability, and operational concerns.

Hints

Hint 1

A raw log row is an attendee record, not a meeting record. Before computing any metric, think about what key uniquely identifies one meeting and how you collapse rows to it — otherwise concurrency and utilization counts will be inflated by the attendee multiplier.

Hint 2

Summing raw durations to compute utilization double-counts overlapping intervals. The correct approach is to take the *union* of intervals per room per window, then measure covered seconds. A line-sweep (sort by time, track active-interval count) achieves this in O(n log n) per room.

Hint 3

A naïve partition on office_id alone concentrates all of a large HQ's traffic onto one reducer. Partitioning on (office_id, day) spreads work proportionally with backfill depth, and map-side combiners on additive deltas (+1/−1) collapse burst keys before the shuffle.