Hard · 10 steps · ~75 min
Design ad click aggregation
Count billions of clicks per window, exactly once, even when events arrive late.
An ad network records every click on every ad and must show advertisers how many clicks each campaign got per minute, while also billing them accurately. Clicks arrive in huge bursts, get retried and duplicated, and sometimes show up late.
Same problem as Google AdsMeta AdsCriteo
How it works
- Ingest: accept a click quickly and acknowledge it.
- Count: group clicks into time windows per campaign.
- Query: advertisers read counts over time, mostly recent ones.
What you'll build
- The API and the data model
- A stream-and-workers pipeline into a time-series store
- A dedup guard in front of the stream
- A fleet that survives a lost worker or broker
- Reasoning about late events, exact vs approximate counts and hot keys
Steps
- 1Design the API
- 2Design the data model
- 3Count clicks at 2,000 per second
- 4Which clock defines a window?
- 5Scale to 50,000 clicks per second
- 6Drop duplicate clicks
- 7Exact or approximate?
- 8Lose a worker at 60,000 clicks per second
- 9Lose a time-series node at 50,000 clicks per second
- 10Deep dive: a hot campaign