System design interview guide
Ad Click Aggregator System Design Interview: Counting a Firehose Without Double-Charging Advertisers
Two courses by the author of this page:
770 lessons · 18 free to read
₹1,111 in India · $35 elsewhere, once
Get System DesignYou own this course
219 lessons · 10 free to read
₹1,333 in India · $35 elsewhere, once
Get Generative AI and Agentic AIYou own this course
Save your progress and get the interview checklist PDF
A large ad network emits an event firehose measured in millions of impressions and clicks per second. Advertisers want a dashboard that updates within seconds, but they are billed on those same numbers, so a click counted twice is money charged twice. The whole design lives in the gap between fast approximate counts and slow exact counts. All throughput figures here are estimates unless a cited source says otherwise.
An ad click aggregator ingests a massive stream of click and impression events, groups them into per ad, per time bucket counts, and serves two audiences from the same data: advertisers watching a near real time dashboard and a billing system that needs numbers it can defend. The core of the design is a durable log (Kafka) that absorbs the firehose and partitions events by ad id, a stream processor (Flink or Spark Structured Streaming) that runs windowed aggregation over event time, and an OLAP store (Druid, Pinot, or ClickHouse) that holds pre aggregated rollups and answers dashboard queries in well under a second. The hard parts are all about correctness under failure. Events arrive out of order and late, so you need watermarks and a grace period to decide when a minute is done. A click must be counted exactly once, so every event carries a stable id and gets deduplicated. A viral ad creates a hot partition that one consumer cannot keep up with. And because streaming counts can drift, most real systems keep a batch reconciliation path (or a replayable single stream) that produces the authoritative billing number a few hours later. The interview is really a tour of stream processing done under a billing constraint.
Where it shows up
Asked at Meta, Google, Amazon, Uber, TikTok, LinkedIn, and most ad tech and data infrastructure teams. It is a staple of senior and staff loops because it forces a candidate to reason about streaming correctness rather than just drawing boxes.
Spec sheetAd Click Aggregator
- 01Impression firehose (peak)
- ~3M events/sec
- 02Click events (peak)
- ~35K events/sec
- 03Ingest bandwidth
- ~600 MB/sec
- 04Aggregate rows per day (per minute grain)
- ~14B rows/day
worked through below, with the maths
in this guide
Design Ad Click Aggregator, part by part
7 parts open to everyone · 3 with a free account · 3 with the course
You can read 7 of 13 parts. A free account opens the deep dive; the course opens all of it.
- Requirementsopen
- Scale estimatesopen
- High-level architectureopen
- Core componentsopen
- Data modelfree account
- Deep dives (7)free account
- Trade-offs to discussfree account
- What the interviewer asks nextwith the course
- The interview scorecardwith the course
- Mock interview on this questionwith the course
- How Ad Click Aggregator actually does itopen
- Frequently asked questionsopen
- Interview readiness checkopen
The hard parts of this design are taught step by step in the System Design course: Watermarking, Exactly-Once Semantics and Stream Processing.
Why this question is asked
Interviewers like this problem because it separates people who have only read about stream processing from people who understand what actually breaks. Almost any candidate can say 'Kafka into Flink into a database.' The signal comes from the follow ups. What happens when an event arrives ten minutes late? How do you know a one minute window is complete if you cannot trust wall clock time? How do you avoid counting the same click twice when a processor crashes and replays? What do you do when one ad goes viral and its partition falls behind while every other partition is idle? The billing angle makes correctness non negotiable, so hand waving gets exposed quickly. It also has natural depth: you can spend the whole hour on windowing and watermarks, or pivot into the Lambda versus Kappa debate, or dig into the OLAP serving layer. Few problems test event time reasoning, idempotency, hot key handling, and the accuracy versus latency tradeoff all at once.
This page is the free part.
The course goes deeper on the Ad Click Aggregator design
₹1,111 in India$35 everywhere elseonce, for the whole course
The System Design course covers the Ad Click Aggregator design across a run of lessons, not one page. These 4 alone are about 105 minutes of step-by-step reading, every one with a quiz.
- Stream Processing
Process data as it arrives, real-time analytics, fraud detection, and event-driven architectures.
- Tumbling Windows
Fixed-size, non-overlapping time windows, count events per minute, average per hour.
- Watermarking
Tracking progress of event time, how stream processors know they have seen all events up to a certain time.
- Exactly-Once Semantics
Processing every event exactly once despite failures, the holy grail of stream processing.
all part of
System Design Masterclass
770 lessons · about 290 hours · 18 free to read
₹1,111in India, by UPI
$35everywhere else, by card or PayPal
You own this course
Continue with Stream Processingpay once,
yours for life
Live from the course bench
Before you design Ad Click Aggregator, try the questions it rests on.
Real interview questions, live diagrams and measured lab results, pulled at random from the lessons. A new set every time you come back.
Requirements
Always clarify these in the first 5 minutes of the interview. Do not start drawing boxes until both lists are agreed.
Functional requirements
- Ingest click and impression events from ad serving endpoints across many regions, on the order of millions of events per second at peak.
- Aggregate counts per ad id per time bucket (per minute, rolled up to hourly and daily) with support for slicing by dimensions like campaign, advertiser, country, and device.
- Serve a near real time dashboard where an advertiser sees clicks and spend updating within a few seconds of the click.
- Produce accurate, reconciled counts that the billing system can charge against, even if that number lags real time by minutes or hours.
- Count each click exactly once so an advertiser is never charged twice for the same event.
- Handle out of order and late arriving events correctly, attributing them to the time bucket they actually happened in.
- Support top N queries such as the highest converting ads in the last hour, and time range queries over arbitrary windows.
- Filter fraudulent and bot traffic (click spam) so it does not inflate billed counts.
- Allow reprocessing of a time range if a bug is found in the aggregation logic, without corrupting already served data.
Non-functional requirements
- High ingest availability. Dropping the endpoint should never block ad serving, so the collector must be fire and forget and the log must absorb bursts.
- Dashboard query latency in the low hundreds of milliseconds at p99 for typical rollup queries.
- End to end freshness for the real time path measured in seconds to low tens of seconds.
- Correctness for the billing path. The reconciled number must be exact and auditable, not approximate.
- Horizontal scalability across ingestion, processing, and storage as event volume grows.
- Durability. No acknowledged event may be lost, since a lost click is lost revenue.
- Fault tolerance. A processor crash must not double count or drop counts on recovery.
- Cost efficiency. Storing every raw event forever is expensive, so raw retention is bounded while rollups are kept long term.
Back-of-envelope scale estimates
Show your math. Pulling numbers from thin air signals you have not thought about the load.
Impression firehose (peak)
~3M events/sec
Estimate for a large network. Assume 100B impressions/day. 100e9 / 86400 = 1.16M/sec average. Apply a 2.5x to 3x peak factor for prime time. Derived, not a published Meta or Google figure.
Click events (peak)
~35K events/sec
Derived from the impression estimate at ~1% click through rate. 100B impressions/day * 1% = 1B clicks/day, /86400 = ~11.6K/sec average, ~35K/sec at 3x peak. Clicks are the billed events and are far rarer than impressions.
Ingest bandwidth
~600 MB/sec
Derived. 3M events/sec * ~200 bytes per serialized event (ids, timestamp, ad id, geo, device, user agent hash) = 600 MB/sec into Kafka before replication. With replication factor 3 the disk write rate is roughly 1.8 GB/sec across the cluster.
Aggregate rows per day (per minute grain)
~14B rows/day
Derived and pessimistic. Assume 10M ads active in a day and 1440 minute buckets: 10e6 * 1440 = 14.4B rows. Real systems are far smaller because most ads are idle in most minutes, so sparse storage plus rollup collapses this by one to two orders of magnitude.
Dashboard query latency target
<200 ms p99
A design target, not a measured number. Achieved by querying pre aggregated rollups in a columnar OLAP store rather than scanning raw events, so a one week trend for one advertiser touches thousands of rolled up rows, not billions of raw ones.
Raw event retention vs rollup retention
~3 to 7 days raw, 13+ months rollup
Estimate driven by cost. Raw events are kept only long enough to reprocess and reconcile (Kafka retention plus a data lake copy). Minute and hour rollups are cheap and kept for year over year reporting and audits.
High-level architecture
An ad event starts at the ad server. When a user clicks, the browser hits a lightweight collector endpoint (often a redirect service that logs the click, then 302s the user to the advertiser landing page). The collector does almost no work: it stamps the event with a server side receive time, validates the payload, attaches a stable event id, and appends it to a Kafka topic partitioned by ad id. Kafka is the buffer that decouples a spiky, always on firehose from the processing layer, and it is also the replay log that makes reprocessing possible. A stream processor, typically Flink, consumes the topic, deduplicates events using their ids against keyed state, and runs tumbling windows (one minute is common) keyed by ad id and dimensions. It uses event time, not processing time, and advances watermarks so it knows when a window can be considered complete despite out of order arrivals. When a window closes, the processor emits a compact aggregate row (ad id, minute, click count, impression count, spend) and writes it to a real time OLAP store such as Apache Druid or Apache Pinot, using an upsert keyed on ad id plus time bucket so retries and late corrections overwrite rather than duplicate. The advertiser dashboard queries that OLAP store directly and gets sub second responses because it reads pre aggregated rollups. In parallel, the raw events also land in a data lake (S3, Hive) so a batch job can recompute the exact numbers later. Billing reads from the reconciled batch output, or from the OLAP store once the streaming counts have stabilized, never from the raw provisional counts. Fraud filtering sits either inline in the stream (fast heuristics) or as a separate scoring job that adjusts counts before billing.
In a real interview, sketch this on the whiteboard before diving into any single box.
Core components
Walk through each service. The interviewer wants to hear what each one owns, not just the names.
Event collector and redirect service
A stateless, horizontally scaled HTTP tier that receives click and impression beacons and writes them to Kafka. For clicks it usually issues a 302 redirect so the user reaches the landing page immediately while the event is logged asynchronously. It must be fire and forget: it acknowledges fast and never blocks on downstream processing, because ad serving latency directly affects revenue.
Kafka ingestion log
The durable, partitioned commit log that absorbs the firehose and orders events within a partition. Partitioning by ad id keeps all events for one ad on one partition so aggregation state is local, and it is what lets Pinot or Druid upsert correctly. Its retention window doubles as the replay buffer for reprocessing and for the batch reconciliation path.
Stream aggregation job (Flink or Spark Structured Streaming)
The heart of the real time path. It reads from Kafka, deduplicates by event id using keyed state, assigns event time, runs windowed aggregation with watermarks, and emits per ad, per bucket counts. It checkpoints its state and Kafka offsets together so a crash and restart resumes without double counting.
Real time OLAP serving store (Druid, Pinot, or ClickHouse)
A columnar store built for fast group by and time range scans over aggregates. It ingests the streaming rollups and makes them queryable within seconds, and it uses upsert on the ad id plus time bucket key so late corrections replace earlier values. This is what the advertiser dashboard actually queries.
Batch reconciliation pipeline
A periodic job (Spark or a warehouse SQL job) that reads the raw events from the data lake and computes exact counts for closed time ranges. It corrects for anything the streaming layer got wrong: dropped watermarks, extreme late arrivals, or fraud rescoring. Its output is the source of truth for billing.
Fraud and click spam filter
A scoring stage that flags bot traffic, duplicate rapid clicks from one device, and click farms. Simple heuristics (rate per device, impossible click through rates) can run inline in the stream, while heavier machine learning scoring runs as a separate job whose verdicts adjust the billed counts before invoicing.
Query and billing API
A service layer that fronts the OLAP store for dashboard reads and exposes the reconciled counts to the billing system. It enforces per advertiser access control, applies currency and spend calculations, and clearly separates provisional real time numbers from finalized billed numbers so nobody is charged off a draft count.
Data model
raw_ad_events. Append only log of every click and impression, keyed by a globally unique event_id used for deduplication. event_time is when it happened, receive_time is when the…
Every table for Ad Click Aggregator, its keys, and which store fits it and why.
Deep dives
Event time versus processing time, and why watermarks are the whole game. The naive design buckets an event by the wall clock time the processor sees it. That is processing time, and it is wrong for billing. A click that happened at 12:00:59…
7 deep dives on the parts that break at scale: Event time versus processing time, and why watermarks are the whole game; Handling late and out of order events without lying to the advertiser; Exactly once and deduplication as a billing requirement.
Trade-offs to discuss
Event time versus processing time. Processing time is simpler and always makes progress, but it attributes events to the wrong buckets under network delay, which is unacceptable when those buckets are…
6 decisions an interviewer expects you to defend, each with the alternative and why it loses here.
What the interviewer asks next
A bug in the aggregation logic has produced wrong counts for the last three days. How do you fix the numbers?
3 follow-up questions with model answers, the interview scorecard for this question, and a mock interview on Design Ad Click Aggregator with the AI tutor.
How Ad Click Aggregator actually does it
Uber published a detailed account of its ad event processing platform built on Apache Flink, Kafka, and Pinot. It runs Flink and Kafka in exactly once mode with read_committed consumers and two phase commit sinks, checkpoints every two minutes (which it calls out as the main reason the system is near real time rather than instant), and attaches a record UUID to every aggregate so Pinot upsert, Hive dedup, and the ad budget service can each reject duplicates. It uses one minute tumbling windows keyed by ad identifier, stores events in Docstore for order attribution, and processes hundreds of millions of ad events per week. The broader design vocabulary comes from Apache Flink's own documentation on event time and watermark generation, from Jay Kreps' Questioning the Lambda Architecture which framed the Kappa alternative, and from the serving layer docs for Apache Druid (ingestion time rollup) and Apache Pinot (stream ingestion with upsert, which Uber contributed). These are the primary references a candidate should anchor on rather than generic blog summaries.
Sources
- Uber Engineering: Real-Time Exactly-Once Ad Event Processing with Flink, Kafka, and Pinot
- Jay Kreps: Questioning the Lambda Architecture (O'Reilly)
- Apache Flink: Generating Watermarks (event time documentation)
- Apache Pinot: Stream Ingestion with Upsert
- Apache Druid: Data Rollup (ingestion-time pre-aggregation)
Lessons to study before this interview
If any of these topics are fuzzy, the interviewer will catch it. Each lesson is 15 to 60 minutes with diagrams, code, and a quiz.
Frequently asked questions
interview readiness
Are you ready for Design Ad Click Aggregator?
Three questions from this guide. Answer them without scrolling up, the way you would have to in the room.
Go deeper
This guide is built on these 5 lessons. Each one teaches one piece of the Ad Click Aggregator design above, step by step.
- Stream ProcessingSystem Design · stream batch processing · 30 min
- Tumbling WindowsSystem Design · stream batch processing · 30 min
- WatermarkingSystem Design · stream batch processing · 20 min
- Exactly-Once SemanticsSystem Design · stream batch processing · 25 min
- Lambda ArchitectureSystem Design · stream batch processing · 48 min
Practice with 770 system design lessons
Lifetime access for ₹1,111 in India or $35 elsewhere. Interactive diagrams, quizzes, and 20 capstone projects to practise on.
This one question is not enough for the interview.
Get all 200 questions in the System Design and Distributed Systems pack
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (268 diagrams in all). A PDF you keep, junior to staff level.
Pay by UPI, cards or netbanking through Razorpay. Pay by card or PayPal, in US dollars. Download at once from My packs.
NEWSystem Design Hands-On
Included in the System Design course: real systems, built live
Postgres Sharding: Complete Hands-On (PgBouncer + Citus). 2 h 36 min and 20 chapters: one PostgreSQL loaded until it breaks, then four shards behind a router you write, PgBouncer and Citus, with the 139-page slide deck. The first 15 minutes are free to watch.


