InterviewDryRun
Lesson 23 · 26 min video · free

Design Ad Click Aggregation

Advertisers pay per click, so every click must be counted quickly for dashboards and exactly once for the invoice. This lesson designs a click pipeline: a fast click logger, a durable event log, a stream processor that counts clicks per ad per minute, an analytics store for queries, and a nightly batch job that recounts everything from raw events so billing is always right.

What you will learn

  • Keep every raw click in a durable, replayable log: it is the source of truth for both counting and billing.
  • Count in a stream processor with event-time windows and a watermark, so late clicks land in the right minute.
  • Exactly-once counting needs a deduplication key per click plus checkpoints that commit state and log offsets together.
  • Run two paths: a fast streaming count for dashboards and a batch recount from raw events for invoices.
  • Reconcile the two daily; billing uses the batch number, and differences are measured and explained.
  • Spread hot ads across several partitions and merge partial counts, so one viral campaign cannot stall a worker.

In this lesson

  1. The question
  2. Step 1: Clarify the requirements
  3. Step 2: Back-of-the-envelope estimates
  4. Step 3: The API and the click event
  5. Step 4: From click to durable log
  6. Step 5: Counting in time windows
  7. Step 6: Late events and watermarks
  8. Step 7: Counting each click exactly once
  9. Step 8: The query store
  10. Step 9: The batch path and reconciliation
  11. Step 10: Filtering invalid clicks
  12. Step 11: One click, end to end
  13. Step 12: Hot ads and scaling
  14. Step 13: Failures
  15. Step 14: The parts people forget
  16. Step 15: The follow-up questions
  17. Recap
Practice this question with Max

The question

Welcome to lesson twenty-three of the InterviewDryRun system design course. Today we design ad click aggregation: the system that counts how many times each ad was clicked, minute by minute, so that advertisers can watch their campaigns live and be billed correctly at the end of the month.

It is a favourite question for senior candidates because it looks simple, just counting, and then turns out to touch nearly every hard idea in data streaming. Events arrive late and out of order. Some arrive twice. Some are fake. The numbers on a dashboard can be approximate for a few minutes, but the numbers on an invoice are money, and they must be exact. Holding both of those requirements in one design is the whole exercise.

Max asks

“Design a system that counts ad clicks in near real time and reconciles them for billing.”

That is how Max, our AI interviewer, asks it. Notice two phrases. Near real time means a delay of seconds to a minute is fine, but not hours. And reconciles them for billing tells you there is a second, slower path whose numbers must agree with the fast one, or at least be explainable when they do not. Many candidates design the fast path well and never mention the second one. Say early that you will design both.

The plan: requirements and numbers, then the API and the click event, then the pipeline from the click to a durable log. Then the core: aggregating in time windows, dealing with late events, and counting exactly once. Then the query store, the batch path and reconciliation, fraud filtering, scaling hot ads, failures, and the follow-up questions Max likes to ask.

Step 1: Clarify the requirements

Functional requirements
  1. 01
    Record every clickAd id, campaign, time, user signals
  2. 02
    Redirect the user fastClicking must never feel slow
  3. 03
    Live countsClicks per ad per minute, within a minute or so
  4. 04
    Query dashboardsBy ad, campaign, advertiser, country, time range
  5. 05
    Billing totalsExact, deduplicated, fraud-filtered, per month

Start with questions.

When a user clicks an ad, we record the click and send the user on to the advertiser's page. Ask what a click record contains: the ad id, the campaign, a timestamp, and signals like the device, country and a hashed user or session id, which we will need for deduplication and fraud checks.

Then the counts. Advertisers want clicks per ad per minute, visible within a minute or so, and they want to slice them: by campaign, by country, over the last hour or the last thirty days. Ask how far back queries go. A common answer is minute detail for a few days, then hourly and daily totals kept for years.

And billing. At the end of each period, each advertiser is charged for valid clicks: deduplicated, with fraud removed. That number must be exact and reproducible. If an advertiser disputes an invoice, we must be able to show where every click came from. That requirement alone tells you to keep the raw events.

Non-functional requirements
  1. 01
    Never lose a clickLost clicks are lost revenue
  2. 02
    Never double-billDuplicates are refunds and angry customers
  3. 03
    Fresh dashboardsAbout a minute behind real time
  4. 04
    Fast redirectsTens of milliseconds
  5. 05
    AuditableEvery billed click traceable to a raw event

The qualities.

Correctness comes first, and it cuts both ways. Losing a click loses money for us. Counting a click twice overcharges the advertiser, which is worse, because it costs trust. So the invariant is: each valid click is billed exactly once.

Freshness is a softer requirement. A dashboard that is a minute behind is fine, and it can even be slightly wrong for a few minutes and then correct itself. The redirect must be fast, because a slow click hurts the advertiser's conversions. And everything must be auditable. Say out loud that the fast path and the billing path have different needs, and that this will shape the design.

Step 2: Back-of-the-envelope estimates

Sizing it
Clicks per day1 billionabout 12,000 a second on average
Peak50,000 / sevenings, big events
Click event sizeabout 300 bytesids, time, device, country, hashes
Raw clicks per day300 GBabout 110 TB a year
Active ads2 millionmost get a handful of clicks a day

Let us size it.

Say one billion clicks a day. Divided by about eighty-six thousand seconds, that is roughly twelve thousand clicks a second on average, and perhaps fifty thousand a second at peak. That is a healthy stream, but nothing exotic for a partitioned event log.

Each click event is about three hundred bytes, so three hundred gigabytes of raw clicks a day, a bit over a hundred terabytes a year. That is cheap in object storage, and we will keep it, because billing and audits need it.

Now the aggregates. Two million active ads, but most get only a few clicks a day. If we keep one row per ad per minute only when the ad had a click, the minute table holds at most a few hundred million rows a day, and in practice far fewer. Hourly and daily rollups are much smaller again. So the aggregated data is tiny compared with the raw data, which is the point of aggregating.

The shape, then: a high, steady stream of small events that must not be lost; a small, query-friendly set of counts; and a large, cheap archive of raw events for recounting. Three kinds of data, three treatments. That sentence is a good way to finish your estimates.

Step 3: The API and the click event

API
GET  /c/{impressionId}?ad=123         → 302 to the advertiser's URL

click event (to the log):
  { clickId, impressionId, adId, campaignId, advertiserId,
    eventTime, country, device, ipHash, userHash }

GET  /v1/ads/{adId}/clicks?from=…&to=…&granularity=minute
GET  /v1/campaigns/{id}/clicks?groupBy=country
GET  /v1/advertisers/{id}/invoices/2026-10

There are three groups of calls. First the click itself. The ad's link points at our click service, with an id that identifies this particular impression. The service records the click and answers with a redirect to the advertiser's page.

The click event carries a click id, generated by the click service, and the impression id, which was created when the ad was shown. That impression id is very useful: one impression should produce at most one billable click. If a user double-clicks, or a browser retries, we see the same impression id twice, and we can deduplicate on it.

The event also carries the event time, meaning when the click happened, as opposed to when we processed it. Keep those two times apart in your head and out loud. Almost every subtle problem in this design comes from the gap between event time and processing time.

Then the query side: clicks for an ad or campaign over a time range, at a chosen granularity, optionally grouped by a dimension like country. And invoices, which come from the billing path, not from the live counts. Making that split visible in the API is a quiet signal that you have understood the question.

Step 4: From click to durable log

Recording a click
GET302appendcopyCLIENTBrowserclicks the adSERVICEClick servicestatelessCLIENTAdvertiser pageQUEUEClick logpartitioned, replicatedSTORERaw archiveobject storageWORKERStream aggregator

Let us follow a click. The user's browser hits the click service, which is a stateless fleet behind a load balancer.

It builds the click event and replies with a redirect to the advertiser's page. Should the redirect wait until the event is safely stored? That is the first real trade-off. Waiting adds a few milliseconds but guarantees the click is recorded. Not waiting is faster but can lose clicks if the server dies.

The usual answer is to append to the click log before redirecting, with the log acknowledging after the event is on more than one machine. Appending to a partitioned log takes a few milliseconds, well within budget. If the log is briefly unreachable, the click service buffers to its local disk and redirects anyway, then forwards the buffer later. A lost click costs money; a five millisecond delay costs nothing.

The click log is the backbone of the design: a durable, append-only, partitioned log that consumers read at their own pace and can replay from any point. Partition it by ad id, so all clicks for one ad go to the same partition, in order. That makes per-ad counting simple, at the cost of hot partitions for very popular ads, which we will fix later.

Two consumers read the log. The stream aggregator counts clicks for the live dashboards. And an archiver copies raw events, in compressed files grouped by hour, into object storage. That archive is what the billing path recounts from, and what we show an advertiser who disputes an invoice. Keep the log itself for a week or so, long enough to replay a few days if a bug is found.

Step 5: Counting in time windows

Kinds of windows
WindowShapeUsed for
Tumblingfixed, back to back: 10:00, 10:01…clicks per minute, the basic count
Hoppingfixed size, overlapping: 5 min every 1 minmoving averages on dashboards
Slidinglast N seconds at any momentalerts: spike in the last 30 s
Sessionends after a gap of inactivityuser behaviour, not needed for billing

Now the core. We want clicks per ad per minute. In stream processing terms, that is a tumbling window of one minute, keyed by ad id.

A tumbling window is fixed and back to back: ten o'clock to ten-oh-one, then ten-oh-one to ten-oh-two. Each click falls into exactly one window. That is what we want for counting, because summing minutes gives exact hours and days.

Hopping and sliding windows overlap, so a click counts in several of them. They are useful for things like a five-minute moving average on a dashboard, or an alert when an ad's clicks spike. Session windows group events by gaps in activity and are for behaviour analysis. Name them briefly, and say tumbling windows are the right tool for counting.

The aggregation, per worker
for click in partition:
    w = floor(click.eventTime, 1 minute)
    if seen(click.impressionId): continue       // dedupe
    state[(click.adId, w)] += 1

on watermark passing w + 1 minute:
    emit (adId, w, count) → analytics store
    keep a small tail of state for late clicks

Inside the aggregator, each worker owns some partitions of the click log. For every click it reads, it adds one to a counter for that ad and that minute, held in its local state. When a window closes, the worker emits a row: ad one-two-three, minute ten-oh-one, forty-seven clicks. Those rows go to the analytics store.

Two questions decide whether this is correct. First, which time do we use for the window: event time or processing time? Second, when is a window closed? A click from ten-oh-one might reach us at ten-oh-four, because a phone was offline. The next step answers both.

Step 6: Late events and watermarks

Event time, done properly
  1. 01
    Window by event timeWhen the click happened, not when we saw it
  2. 02
    Watermark'No more events older than T are expected'
  3. 03
    Allowed latenessAccept stragglers for a while, update the count
  4. 04
    Too lateSend to a side output; the batch path counts them

Use event time. If we counted by processing time, a slowdown in the pipeline would shift clicks into the wrong minutes, and a replay of yesterday's log would count every click as happening today. Event time makes the result depend only on the data, which is what lets the fast path and the batch path agree.

But with event time, when can we close the ten-oh-one window? We never know for sure that no more clicks from that minute will arrive. So the stream processor tracks a watermark: an estimate that says all events older than time T have probably arrived. A simple watermark is the latest event time seen minus a fixed delay, say thirty seconds. When the watermark passes ten-oh-two, the ten-oh-one window is emitted.

Some clicks still arrive after that. Allow lateness for a while, perhaps ten minutes: keep the window's state, and when a late click arrives, update the count and emit a corrected row. The analytics store must accept updates, not just inserts, so emitted rows are keyed by ad and minute and simply overwritten.

After the allowed lateness, the state is dropped. Clicks that arrive even later, from a phone that was offline for an hour, go to a side output and are logged. They are not lost: they are in the raw log and the archive, so the batch recount includes them. This is a nice point to make: the stream path can afford to be slightly incomplete, because the batch path is the safety net.

The trade-off to state clearly: a longer watermark delay makes the first number more complete but the dashboard more stale. A shorter one makes it fresher but more often corrected. For dashboards, a thirty second delay with ten minutes of allowed lateness is a sensible default. Interviewers like hearing that this is a dial, not a fact.

Step 7: Counting each click exactly once

Where duplicates come from
  1. 01
    User sideDouble clicks, browser retries, bots
  2. 02
    Pipeline sideA worker crashes and re-reads the log
  3. 03
    Fix for the user sideDeduplicate on impression id
  4. 04
    Fix for the pipeline sideCheckpoint state and offsets together

Now the hard part. Duplicates come from two very different places, and you should separate them clearly.

The first source is the user. Someone double-clicks, or a browser retries a request, so the same impression produces two click events. These are real events in the log, and the business rule says only one is billable. We deduplicate on the impression id: the aggregator remembers the impression ids it has counted, for as long as a duplicate could plausibly arrive, say an hour.

Remembering a billion ids a day sounds expensive, but we only need recent ones, and they are partitioned along with the ad. Each worker keeps a set of impression ids seen in the last hour, in its local state, which is a few hundred megabytes spread over the fleet. A probabilistic filter could shrink it further, but a filter can wrongly say we have seen an id, which drops a real click, so for billing-grade counts use an exact set.

The second source is our own pipeline. A worker reads a thousand clicks, updates its counters, and crashes before recording how far it got. Its replacement re-reads those thousand clicks, and without care counts them twice. This is a duplicate we created ourselves.

Exactly once, end to end
checkpoint every 10 s:
    save { counters, seen impression ids, log offsets }  atomically

crash → restore last checkpoint → re-read from saved offsets

sink: upsert (adId, minute) = count     // idempotent
      a replayed window writes the same row again

The fix is checkpointing. Periodically, every few seconds, the stream processor saves a consistent snapshot of every worker's state, the counters and the impression id sets, together with the log offsets that state corresponds to. After a crash, it restores the last snapshot and re-reads the log from those offsets. The counters and the position move together, so nothing is counted twice and nothing is skipped.

One more piece: the output. After a restore, windows may be emitted a second time. If the analytics store added the counts, that would double them. So the write must be idempotent: an upsert of the row for this ad and this minute with the full count, not an increment. Writing the same row twice leaves the same result. Checkpoints plus idempotent output is what people mean by exactly-once processing, and it is worth saying that sentence in exactly those words.

Step 8: The query store

Where the counts live
TableKeyKept for
clicks_minuteadId, minute, country7 days
clicks_houradId, hour, country13 months
clicks_dayadId, day, countryyears
billing_dailyadvertiserId, adId, dayforever, from the batch path

The aggregated rows need a home that answers dashboard queries fast: sum the clicks for this campaign over the last seven days, grouped by country.

A column-oriented analytics store fits well. It stores each column separately and compressed, so a query that sums one column over millions of rows reads only that column. Partition tables by time, and sort by ad id within each partition, so a query for one ad over a week touches a small, contiguous slice.

Keep rollups. Minute rows are kept for a week, then rolled up into hourly rows kept for over a year, and daily rows kept for years. A query for the last thirty days reads hourly rows, seven hundred and twenty per ad, instead of forty-three thousand minute rows. Rollups are a background job that sums the finer table into the coarser one, and because sums are exact, nothing is lost.

The billing table is separate, and it is filled by the batch path, not by the stream. Dashboards read the fast tables. Invoices read the billing table. If the two disagree slightly for yesterday, the dashboard can show the billing number once it exists. That is how the user-facing numbers settle on the exact answer within a day.

Advertisers also ask for breakdowns we did not precompute, say clicks by device for one campaign. Keep the most-used dimensions, like country and device, in the aggregate key, because each extra dimension multiplies the number of rows only for ads that actually have that variety. Rare, ad hoc questions can run against the raw archive with a batch query engine. They are slower, but they are rare.

Step 9: The batch path and reconciliation

Two paths, one source
QUEUEClick logWORKERStream aggregatorsecondsSTORERaw archivehourly filesSTORELive countsdashboardsWORKERDaily batch jobdedupe + fraudSERVICEReconcilercompare, alert

Now the reconcile half of the question. Once a day, a batch job recounts yesterday's clicks from the raw archive, from scratch.

Why count twice? Because the batch job has advantages the stream does not. It sees every click for the day, including the ones that arrived hours late. It can deduplicate across the whole day, not just a one hour window. It can apply the fraud model's final verdicts, which may arrive hours after the click. And it can be rerun at any time with the same input and get the same answer.

The batch output is the billing truth: valid clicks per ad per day. The reconciler then compares it with the stream's totals for the same day. Small differences are expected: late clicks and fraud removed after the fact. A difference of a fraction of a percent is normal. A difference of five percent means something broke, perhaps a deduplication bug or a partition that stopped being consumed, and it raises an alert before an invoice goes out.

This pattern, a fast approximate path and a slow exact path over the same immutable log, has a name in some textbooks, but the name matters less than the reasoning: speed and correctness have different costs, and an immutable raw log lets you have both. Some teams instead run a single streaming path and trust it for billing; that can work, but you still want the batch recount as an audit, and saying so is the safer answer.

Invoices are then generated from the billing table at the end of the month, multiplying valid clicks by each ad's agreed price, with budget caps applied: if an advertiser's daily budget is a hundred dollars, clicks beyond that are not billed, even though they are counted. Keep pricing and budgets in the billing service, not in the counting pipeline.

Step 10: Filtering invalid clicks

Invalid click filtering
  1. 01
    At click timeKnown bad IPs, data centres, impossible rates
  2. 02
    In the streamBursts per user, per IP, per ad, within minutes
  3. 03
    In batchModels over the whole day, patterns across publishers
  4. 04
    ResultClicks marked invalid, kept, never billed

Not every click is a person interested in an ad. Some are bots, some are competitors draining a budget, some are publishers clicking their own ads for money. Advertisers expect us to not bill those.

Filtering happens at three speeds. At click time, cheap rules: requests from known data-centre address ranges or known bad devices are marked invalid immediately, but still recorded, and still redirected, so a bot learns nothing.

In the stream, rate rules over short windows: the same user clicking the same ad twenty times in a minute, or one address producing thousands of clicks across many ads. A sliding window per user or per address catches these within seconds, and the live counts can exclude them quickly.

In batch, heavier models over the whole day: a publisher whose clicks never lead to any activity on the advertiser's site, or clicks clustered in suspicious ways across accounts. These verdicts come hours later, which is exactly why billing uses the batch count.

Two principles to state. Never delete invalid clicks; mark them, with the reason, because an advertiser may ask why we did not bill something, and the reasons improve the models. And keep the fraud rules out of the critical path of the redirect, because a slow fraud check would hurt every legitimate click.

Step 11: One click, end to end

One click, from tap to invoice
WhenWhat happens
10:01:07user taps ad 123; click event appended; 302 sent
10:01:07.02event replicated in the click log, partition 41
10:01:08aggregator: impression not seen; ad 123, 10:01 += 1
10:02:30watermark passes 10:02; row (123, 10:01, 47) upserted
10:02:31advertiser's dashboard shows 47 clicks for 10:01
next day 02:00batch recount: 46 valid (one bot); reconciled

Let us follow one click all the way through, because it ties every piece together.

At one minute and seven seconds past ten, a user taps ad one-two-three. The click service builds the event, with a fresh click id and the impression id from the ad's link, and appends it to the click log. The log replicates it to two more machines and acknowledges. The user is redirected about twenty milliseconds after the tap.

A second later, the aggregator worker that owns partition forty-one reads the click. It checks the impression id against its recent set, finds it new, and adds one to the counter for ad one-two-three, minute ten-oh-one. At half past ten-oh-two, the watermark passes the end of that minute, and the worker upserts the row: forty-seven clicks. A second later, the advertiser's dashboard shows it.

Meanwhile, the archiver has written the raw click into the ten o'clock file in object storage. At two in the morning, the batch job counts the whole day. It finds that one of those forty-seven clicks came from an address the fraud model flagged overnight, so the billable count is forty-six. The reconciler sees a difference of one click in forty-seven, explained by fraud, which is within tolerance. The invoice uses forty-six. Every number can be traced to raw events.

Step 12: Hot ads and scaling

Scaling the counting
  1. 01
    Partition by ad idEven load for millions of ads
  2. 02
    Hot ad problemOne viral ad, one partition, one busy worker
  3. 03
    Salt the keyadId + random 0..7 spreads it over 8 partitions
  4. 04
    Two-stage countPartial counts per salt, merged per minute

Scaling the pipeline is mostly about partitions. Fifty thousand clicks a second over, say, a hundred and twenty-eight partitions is a few hundred a second each, which a single worker handles easily. Add partitions and workers as traffic grows.

The catch is a hot ad. A big brand's campaign during a sports final might get thousands of clicks a second, all keyed to one ad id, so all landing on one partition and one worker. That worker falls behind, and its dashboard lags.

The fix is salting. For ads known to be hot, or detected as hot, append a small random number to the key, say zero to seven, so the ad's clicks spread across eight partitions. Each partition counts its own share. A second, small stage then merges the eight partial counts per ad per minute into one. Since counting is a simple sum, merging partial counts is exact.

The same two-stage idea helps rollups and campaign totals: workers pre-aggregate, and a merge step combines. It is the same trick a map and reduce job uses, and naming the general idea, pre-aggregate where the data is and merge small results, shows you can reuse it beyond this question.

Step 13: Failures

What breaks
  1. 01
    Click service diesStateless; load balancer moves traffic
  2. 02
    Log unreachableBuffer to local disk, forward later
  3. 03
    Aggregator crashesRestore checkpoint, replay from offsets
  4. 04
    Bug in countingFix, replay the log or recount from archive
  5. 05
    Region outageClicks logged in another region; merged by event time

Let us go through what breaks.

Click service servers are stateless, so losing one just shifts traffic. If the log is briefly unreachable, each click server buffers events to local disk and forwards them when it recovers. Those clicks arrive late, but event time puts them in the right minute.

If an aggregator worker crashes, the stream processor restores the last checkpoint and replays from the saved offsets, as we discussed. The dashboard pauses for a few seconds for that worker's partitions, then catches up.

The most interesting failure is a bug: say a release miscounted clicks for six hours. Because the raw log is immutable and kept, the fix is to correct the code and reprocess. Replay the log from before the bug into a fresh set of counts, then switch the dashboard to them. For older data, rerun the batch job over the archive. Being able to recompute from raw events is the strongest reliability property in the design, and it is worth naming.

And a region outage. Clicks are served by the nearest region, each with its own log. If a region fails, its clients fail over to another region, and the counts merge by event time. Raw archives from every region land in one place for billing, so the batch path sees everything.

Step 14: The parts people forget

Easy to miss
  1. 01
    Time zonesStore UTC; advertisers' days are in their time zone
  2. 02
    BudgetsStop serving ads near the cap, not after
  3. 03
    PrivacyHash identifiers; delete raw user data on schedule
  4. 04
    MonitoringConsumer lag, late-event rate, reconciliation gap

A few points that separate a good answer from a great one.

Time zones. Store every timestamp in UTC, and keep hourly aggregates, so you can build a day in any time zone by summing hours. An advertiser in Mumbai and one in New York have different days, and invoices must follow the contract.

Budgets. If an advertiser has a daily budget, the ad server needs to know the spend so far, quickly, to stop showing the ad. That uses the live counts, which may lag by a minute, so stop slightly before the cap, and do not bill the small overshoot.

Privacy. Store hashed identifiers, not raw addresses, where you can, and delete raw user-level data after the retention period the law and your policy allow, while keeping the aggregates. And monitoring: the lag of each consumer behind the log, the share of late events, and the daily reconciliation gap are the three numbers that tell you whether the pipeline is healthy.

Step 15: The follow-up questions

Max asks

“How would you show advertisers the top ten ads by clicks in the last five minutes, updated every few seconds?”

That is a top-k over a sliding window. Each aggregator worker keeps per-ad counts for the last five minutes in small time buckets, say ten seconds each, and every few seconds computes its local top ten. A small merge step combines the local lists into a global top ten. Merging local top tens is approximate in theory, because an ad could be eleventh everywhere and first overall, so each worker sends its top fifty to give a safe margin. For exact results over a whole day, use the batch path.

Max asks

“The click log loses a partition's data. What happens to billing?”

That should not happen, because the log replicates every partition to three machines across failure domains and acknowledges only after two have the event. But if it did, the archive files already written are safe, and click servers that buffered locally can resend. For the gap that remains, the honest answer is that those clicks are lost, so we do not bill for them, and we alert. Never estimate billable clicks; under-billing is the safe side.

Max asks

“Why not just increment a counter in a database for every click?”

At fifty thousand writes a second, many hitting the same row for a hot ad, a database row lock becomes the bottleneck, and every retry risks a double count. We would also lose the raw events, so we could not deduplicate across the day, filter fraud after the fact, or recount after a bug. Counting from an immutable log fixes all of those, and the database only receives a small number of upserts, one per ad per minute.

Max asks

“An advertiser says our click count is higher than the visits their own site recorded. How do you answer?”

Some gap is normal: users who close the page before it loads, blockers on the advertiser's site, and different time zones or definitions. Our side shows the evidence: raw clicks for their ads, the ones we marked invalid and why, and what we billed. If the gap is unusually large for one publisher, that is a fraud signal worth investigating, and refunding it if confirmed builds trust. This question tests whether you designed for audits.

Recap

Your 45 minutes
  1. 01
    0 to 5: requirementsLive counts, exact billing, auditable
  2. 02
    5 to 10: estimates50,000 clicks/s; raw 300 GB a day
  3. 03
    10 to 20: ingest and windowsDurable log; tumbling windows by event time
  4. 04
    20 to 35: correctnessWatermarks, dedupe, checkpoints, idempotent upserts
  5. 05
    35 to 45: billing and scaleBatch recount, reconciliation, fraud, hot ads

On the clock: five minutes on requirements, with the invariant each valid click billed exactly once. Five minutes of numbers: fifty thousand clicks a second at peak, small aggregates, a big raw archive.

Ten minutes on the ingest path and windowing: append to a durable log before redirecting, partition by ad, and count in tumbling windows by event time.

Fifteen minutes on correctness: watermarks and allowed lateness, deduplication by impression id, checkpoints and idempotent upserts. And ten minutes on the batch recount, reconciliation, fraud filtering and hot ads. If you explain why billing comes from the batch path while dashboards come from the stream, you will stand out.

Event time, watermarks and exactly-once counting are hard to explain clearly under pressure. Practicing out loud is how you find the right words. You can practice this exact question with Max, our AI interviewer, at interview dry run dot com. It is free to start, and you get a scored report with what to fix. The written lesson, with every diagram, is on the site too. See you in lesson twenty-four.

Now say it out loud

Watching an answer is not the same as giving one. Max asks this exact question, pushes back when an answer is vague and keeps time, then scores you per skill.

Practice with Max

Free: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.