KatInterview

Real-Time Ad Engagement Counting Pipeline and Advertiser Dashboard

System DesignModel answer
MediumModel answerSystem Designsystem-designstreamingkafka

Last updated

Design a pipeline that ingests millions of ad click events per second and serves near-real-time, windowed counts per ad to advertisers, with deduplication and late-data handling.

Scenario

You are building the measurement backbone of a large ad network. Every time a user clicks an ad, an event must be recorded, and advertisers need a dashboard that shows how their ads are performing almost immediately.

Event fields

Each click carries:

  • ad_id
  • user_id
  • timestamp
  • geo
  • device_type

What the system must do

  1. Collect click events from clients.
  2. Roll up click counts per ad_id into 1-minute, 5-minute and 1-hour buckets.
  3. Serve today's numbers to advertisers with query latency under 500 ms.

Constraints

  • Peak load is 5 million clicks per second.
  • At-least-once delivery is acceptable, but double-counting should be kept to a minimum.
  • Dashboard values should lag reality by only a few seconds.
  • History must be kept for at least 90 days for reporting.

What to cover in your answer

  • A text description of the high-level architecture.
  • The data model for the event stream and for the storage layers.
  • How you absorb the write volume and partition the data, including what happens with very popular ads.
  • How you deal with late or out-of-order events.
  • Any trade-offs you are making, and how you would verify that the counts are correct.

Hints

Hint 1

Do the arithmetic first: events per second times bytes per event gives bandwidth and daily volume. This tells you raw events belong in cheap storage and dashboards must read pre-aggregated rows.

Hint 2

Duplicates come from retries under at-least-once delivery. Think about an identifier created once at the edge and a bounded-memory way to remember recently seen identifiers.

Hint 3

Separate event time from arrival time. Consider watermarks, a bounded lateness window that updates earlier results by overwriting rather than adding, and a batch job that recomputes buckets from raw data for very late arrivals.

Hint 4

One viral ad can overload the partition that owns it. Consider splitting its key across several sub-keys, aggregating partially, then merging.