Quick revision
The short answer
10 billion clicks a day is about 115,000 per second on average, with peaks several times higher. Click servers append each event to a partitioned durable log such as Kafka and redirect the user immediately, a stream processor such as Flink groups by ad in one-minute event-time windows, deduplicates by click id, applies fraud filters and writes per-minute counts to an analytics store, and a query API serves time-bucketed counts with minutes rolled up into hours and days. Raw events are kept in object storage for reprocessing and billing disputes.
What to remember
In this answer, we sized 10 billion clicks a day at about 115,000 per second on average and planned for several times that at peak. Click servers append each event to Kafka and redirect at once, a stream processor groups by ad into one-minute event-time windows, deduplicates by click id, applies fraud filters and upserts per-minute counts into an analytics store, and a query API serves minutes, hours and days from rolled-up tables. Raw events kept in object storage make reprocessing and billing disputes possible.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
10 billion clicks a day is about 115,000 per second on average, with peaks several times higher. Click servers append each event to a partitioned durable log such as Kafka and redirect the user immediately, a stream processor such as Flink groups by ad in one-minute event-time windows, deduplicates by click id, applies fraud filters and writes per-minute counts to an analytics store, and a query API serves time-bucketed counts with minutes rolled up into hours and days. Raw events are kept in object storage for reprocessing and billing disputes.
Why this question is asked
Ad click counting looks like a simple counter until we remember that the counts are money. Advertisers pay per click, budgets are paced from the numbers, and a disputed invoice needs evidence. At the same time the volume is enormous and the user who clicked must reach the landing page instantly. Interviewers ask this because it combines high-throughput ingestion, stream processing with windows and deduplication, and analytics storage in one problem. In this answer, we will size the load, design ingestion, aggregate with a stream processor, store and query the counts, and keep raw events for reprocessing and audits.
1Requirements and Rough Numbers
We must count clicks per ad per minute, available to advertisers within about a minute, count each valid click exactly once, and let the user reach the advertiser's page without delay. 10 billion clicks a day divided by 86,400 seconds is about 115,000 per second. Traffic follows the day, with evening peaks perhaps 3 to 5 times the average, so we design for around 500,000 events per second.
Each event carries a click id, ad id, campaign id, a device or user id, a timestamp, and context such as country, placement and user agent, perhaps 300 bytes. That is about 3 TB of raw events per day. The aggregates are tiny in comparison: even a million active ads with one row per minute is 1.4 billion rows per day before rollups, and most ads are idle most minutes.
- Click serverslog the click, redirect at once
- Kafkaclicks topic partitioned by ad id, 7 days retention
- Stream processorevent-time minute windows, dedup, fraud filters
- Analytics storeper-minute counts, rolled up to hours and days
- Query APIGET /ads/{id}/stats for dashboards and pacing
- Object storageraw events for reprocessing and audits
6 layers, from the top down. Step through them one at a time.
2Ingestion: Record, Then Redirect
When a user clicks an ad, the browser goes to our click server, which must send the user on to the landing page as fast as possible. So the click server does only two things: it appends the event to Kafka and returns an HTTP 302 redirect. Validation, counting and fraud checks all happen later, asynchronously.
5 messages in order. Play them, or step through them one at a time.
The user never waits for counting, only for one durable append.
Notice that the click server waits for Kafka to acknowledge the append before redirecting, so a click that the user saw succeed is never lost. With acks from the in-sync replicas this adds a few milliseconds. The click id is generated when the ad is served and embedded in the link, so a repeated request for the same click carries the same id, which matters for deduplication.
3Aggregating in a Stream Processor
A stream processor such as Apache Flink reads the clicks topic and keeps state. It groups events by ad id into one-minute windows based on event time, the timestamp of the click itself, not when it arrived, so that a click delayed in a phone's network still counts in the right minute. Inside each window it drops duplicates by click id and filters out clicks that fraud rules reject, such as a burst of clicks from one device on one ad.
When a window closes, the processor writes the per-minute count to the analytics store with an upsert keyed by ad and minute, so writing the same window twice after a restart replaces the value instead of adding to it.
Notice the watermark with 30 seconds of out-of-orderness: the processor waits that long past the end of a minute before emitting it, which covers most delayed events while keeping counts available within about a minute. Very late events need extra handling, which the y10 version of this question covers.
4Storing and Querying the Counts
Per-minute counts go to a store built for time-bucketed aggregates, such as ClickHouse, Apache Druid or Apache Pinot. They store data in columns, compress it well and sum millions of rows per second, which is what a 'clicks per day for this campaign over 90 days' query needs. A rollup job sums minutes into hours and hours into days, and old minute rows are dropped after, say, 30 days, because nobody needs minute detail for last year.
The API chooses the table from the granularity and range, so a 90-day daily query reads 90 rows per ad rather than 129,600 minute rows. Dashboards and the budget pacing service both read from here.
5Keeping Raw Events
The aggregates are what advertisers see, but the raw events are the evidence. A copy of every event goes from Kafka to object storage such as S3, in columnar files partitioned by hour. Kafka itself keeps 7 days for quick replay; object storage keeps months or years, as billing rules require.
This is what lets us fix mistakes. If a fraud rule is improved or an aggregation bug is found, we recompute the affected windows from the raw events with a batch job and replace the aggregates. And when an advertiser disputes an invoice, we can show the individual clicks behind the number. Without raw events, every correction would be a guess.
6Follow-up questions
Why partition Kafka by ad id?
So that all clicks for one ad go to the same partition and therefore the same processor instance, which keeps per-ad state such as counts local. The risk is a very popular ad creating a hot partition; with hundreds of partitions this is usually fine, and a truly hot ad can be pre-aggregated per partition with a random suffix and merged afterwards.
Why not just increment a counter in Redis for each click?
It would count quickly, but it gives no event-time windows, no deduplication by click id over time, no fraud filtering and nothing to replay when something goes wrong. For money, we need a pipeline that can be audited and recomputed, which counters alone cannot offer.
How are impressions handled?
The same way, through their own topic and windows, at much higher volume, often ten to a hundred times clicks. Click-through rate is then computed at query time from the two aggregate series.
7Conclusion
In this answer, we sized 10 billion clicks a day at about 115,000 per second on average and planned for several times that at peak. Click servers append each event to Kafka and redirect at once, a stream processor groups by ad into one-minute event-time windows, deduplicates by click id, applies fraud filters and upserts per-minute counts into an analytics store, and a query API serves minutes, hours and days from rolled-up tables. Raw events kept in object storage make reprocessing and billing disputes possible.
Open with
Ten billion clicks a day is about 115,000 per second on average, and with evening peaks I would design for around half a million per second. Each event carries a click id, ad id, campaign, a device or user id, a timestamp and context, a few hundred bytes, so about three terabytes of raw data a day.
Then, if they want more
On ingestion, the click server only appends the event to a partitioned durable log, Kafka keyed by ad id, waits for the acknowledgement and immediately redirects the user to the landing page; nothing else happens on the user's path.
Aggregation is a stream processor like Flink: it assigns event-time timestamps with a watermark allowing some out-of-orderness, deduplicates by click id, applies fraud filters, and counts per ad in one-minute event-time windows, writing each window as an upsert keyed by ad and minute so a replay does not double count.
The counts go to an analytics store built for time-bucketed aggregates, such as ClickHouse or Druid, and rollup jobs build hourly and daily tables. The query API is GET /ads/{id}/stats with from, to and granularity, and it reads the right rollup for the range.
Finally, every raw event is copied to object storage, because billing disputes and corrections need the source data, and with it we can recompute any window.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the ingestion, aggregation and query path of an ad click aggregation system for...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/9daf965af9/