Question presented to candidate:
"Advertisers pay per click, so we need click counts per ad per minute, and the top 100 most-clicked ads in the last minute, for about a billion clicks a day. The numbers feed billing. Design the aggregation system."
What a strong answer should cover:
Capacity: about 11,600 clicks per second on average and several times that at peak, around 200 GB a day of raw events, and the size of the aggregated tables
A pipeline of an append-only click log (partitioned by ad), a stream aggregator with event-time tumbling windows, an OLAP store for aggregates, and a query service; the raw log kept in cheap storage
Correctness under real-world disorder: watermarks, allowed lateness with corrections, a side path for events that are too late, and why processing-time windows put clicks in the wrong minute
Deduplication by click ID and an end-to-end exactly-once effect (idempotent upserts or transactional writes), because billing cannot double count
Reconciliation: a batch job recomputes from the raw log and corrects the streaming numbers; hot ads handled with split keys and two-stage aggregation; top-N computed per partition and merged
Clarifying questions expected:
How fresh must the numbers be, and how exact: is a dashboard estimate acceptable while billing waits for the reconciled number?
How late can a click arrive (mobile clients offline), and must late clicks still be billed?
Which filters must queries support (country, device, campaign)?
Code / implementation expected: Optional — the example implements event-time windows with a watermark, allowed lateness, dedup, top-3 per minute and a batch reconciliation, in four languages.
system-design
case-study
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Intermediate engineers preparing for system design rounds — you know what a queue and a database are; every streaming term is defined when it first appears.
Difficulty: Hard
Verified with: Node 22.22, Python 3.12, Go 1.24 and Java 21 (all four print identical output). Traffic figures are stated assumptions. Apache Flink windowing behaviour (allowed lateness, late-data side outputs) is from the Flink windows documentation, checked October 2026.
How to read this doc: Plain language first, then 📌 Interview term: callouts with the vocabulary interviewers use for stream processing. All counts come from the example program; the Verified section quotes its full output.
1. Why This Even Matters — A Story First
A city counts cars crossing a bridge each minute, to bill a toll per crossing. Cameras at both ends write each crossing on a slip with the t
The solution is hidden so you can try first
15 min read · 16 sections
4
Read the code
Ad click aggregation: event-time windows, watermark, allowed lateness, dedup, top ads per minute and batch reconciliation