Quick revision
The short answer
We fix forward first, then recompute the affected windows from retained raw events by replaying the log or running a batch job over object storage, and write corrected aggregates with a new version so the correction is traceable. Each advertiser's overcharge is computed from the corrected counts, credits are issued, pacing resumes from corrected spend, and advertisers are told before they find it. To catch such errors in minutes, streaming counts are reconciled hourly against an independent count with alerts per ad format, new aggregation logic runs in shadow before switching, and raw events are kept longer than the detection, correction and dispute windows combined.
What to remember
In this answer, we contained the double-counting incident by fixing forward and scoping it, recomputed the affected windows from retained raw events with deduplication by click id, and wrote corrected aggregates with a version and a reason. We computed each advertiser's overcharge, issued credits, resumed pacing from corrected spend and told advertisers first. To catch the next error in minutes, we reconcile streaming counts hourly against an independent count per ad format, release new aggregation logic in shadow before switching, and keep raw events longer than the detection, correction and dispute windows combined.
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.
We fix forward first, then recompute the affected windows from retained raw events by replaying the log or running a batch job over object storage, and write corrected aggregates with a new version so the correction is traceable. Each advertiser's overcharge is computed from the corrected counts, credits are issued, pacing resumes from corrected spend, and advertisers are told before they find it. To catch such errors in minutes, streaming counts are reconciled hourly against an independent count with alerts per ad format, new aggregation logic runs in shadow before switching, and raw events are kept longer than the detection, correction and dispute windows combined.
Why this question is asked
A double-counting bug in ad aggregation is worse than a wrong dashboard, because the numbers drive money twice: advertisers are billed on them, and budget pacing spends their money based on them. Six hours of inflated counts means budgets ran out early, ads stopped showing, and advertisers saw numbers we now have to take back. Interviewers ask this to see whether we can repair data and money methodically, and whether we design the system so the next error is caught in minutes and repaired from evidence, not guesswork. In this answer, we will contain the incident, recompute the data, correct the money, add detection through reconciliation, release changes safely with shadow runs, and set raw-event retention.
1Contain First: Fix Forward and Scope
The first hour is about stopping the damage and knowing its size. We fix forward, deploying a corrected job or rolling back to the previous version, so new windows are counted correctly. Then we scope: which ad format, which windows (the six hours since the deployment), which advertisers and campaigns, and how much pacing spent on top of what it should have.
We also pause anything that would make it worse, such as invoices for the current period being generated from the inflated numbers. Only then do we start repairing, because a repair that runs while the bug is still live has to be repeated.
2Recomputing the Affected Windows
Because we keep raw events, repair is a computation, not an estimate. We recompute the six hours from the source: either by replaying the Kafka topic from the offsets at the start of the incident through the corrected job, or by running a batch job over the raw events in object storage, which avoids competing with live traffic.
The corrected aggregates are written with a version, not as silent overwrites. Each row carries the version of the logic that produced it, and the API serves the latest version while the previous one stays available for audit.
Notice the count(DISTINCT click_id). Recomputing from raw events with deduplication by click id is the independent truth here; it does not depend on the logic that failed. The reason column ties every corrected row to the incident, so anyone who asks why a number changed gets an answer.
3Correcting the Money
With corrected counts, each advertiser's overcharge is the difference between what they were charged and what the corrected counts justify, per campaign. We issue credits for that amount, and the pacing service resumes from corrected spend, so campaigns that stopped early get their remaining budget back and start delivering again.
Then we tell advertisers, proactively and before they find it: what happened, the period, the corrected numbers and the credit. An advertiser who discovers an overcharge on their own assumes the worst; one who hears it from us with the credit already applied usually accepts it as a handled incident.
| Item | Inflated | Corrected |
|---|---|---|
| Clicks counted, 08:00 to 13:10 | 50,000 | 25,000 |
| Spend at 0.40 per click | 20,000 | 10,000 |
| Daily budget 20,000 | exhausted at 13:10 | 10,000 remaining |
| Action | none taken at the time | credit 10,000, pacing resumes from corrected spend |
4Detecting in Minutes Through Reconciliation
Six hours passed because nothing compared the streaming numbers with anything else. The fix is reconciliation: an independent count of the same thing, compared regularly. Every hour, a job counts clicks per ad format from a different source, such as the click servers' own request logs or a parallel batch job over raw events, and compares with the streaming aggregates.
The comparison is per ad format, not only in total, because a doubled format that is 5 percent of traffic changes the total by only 5 percent, which can hide in normal variation. With per-format thresholds, a doubling is a 100 percent deviation and pages someone within the hour, or within minutes if we reconcile every 10 minutes on a sample.
- Stream counts per format for the hourfrom the analytics store
- Independent count per formatclick-server logs or batch over raw events
- Deviation above 1% for any format?after allowing for late dataYesPage the owner, freeze billing for itNoRecord and continue
- Investigate and recomputeversioned correction if needed
4 steps in order. Play them, or step through them one at a time.
5Releasing Aggregation Changes Safely
The bug came from a change, so changes to aggregation logic get a safer path. A new version first runs in shadow: it consumes the same input as production and writes to a separate output that nobody bills from. A comparison job checks the two outputs per ad format for a day or more. Only when the differences are zero, or exactly the ones the change intended, do we switch production to the new logic.
Shadow runs cost extra compute for the duration of the comparison, which is small compared with one incident like this. They also give reviewers concrete evidence instead of a code diff to reason about.
6Keeping Raw Events Long Enough
All of the repair depended on raw events. So their retention must cover the longest time it could take to detect an error, plus the time to correct it, plus the billing dispute period. If detection could take up to a month in the worst case, correction a week, and advertisers can dispute invoices for 90 days after the month ends, raw events must be kept for at least four to five months, and many companies keep them for a year or more for audits.
Raw events in compressed columnar files in object storage are cheap enough that this is rarely a hard decision. The expensive mistake is discovering that the evidence for a disputed invoice was deleted a week earlier.
7Follow-up questions
Why version the aggregates instead of overwriting them?
Overwriting erases the evidence of what advertisers saw and were billed. With versions, we can show exactly which numbers changed, why and when, which is what auditors and advertisers ask. Queries simply read the latest version.
Should we recompute through the streaming job or a batch job?
Either works if both use the same rules. A batch job over object storage avoids loading the live Kafka cluster and is easy to run for a precise time range. Replaying through the streaming job proves that the fixed job itself produces the right numbers. Many teams do the batch recompute and use the replay as a test.
What if the independent count is also wrong?
Then the two disagree and someone investigates, which is the point. Reconciliation does not need a perfect source; it needs two sources that fail differently, so a single bug cannot corrupt both in the same way.
8Conclusion
In this answer, we contained the double-counting incident by fixing forward and scoping it, recomputed the affected windows from retained raw events with deduplication by click id, and wrote corrected aggregates with a version and a reason. We computed each advertiser's overcharge, issued credits, resumed pacing from corrected spend and told advertisers first. To catch the next error in minutes, we reconcile streaming counts hourly against an independent count per ad format, release new aggregation logic in shadow before switching, and keep raw events longer than the detection, correction and dispute windows combined.
Open with
First I contain it: fix forward or roll back the job so new windows are right, scope exactly which ad format, hours, advertisers and campaigns were affected, and pause invoices for that period.
Then, if they want more
Then I recompute the six hours from retained raw events, either replaying Kafka from the incident start through the fixed job or running a batch over object storage, deduplicating by click id, and I write the corrected aggregates as a new version with the incident reference, so the change is traceable and nothing is silently overwritten.
For the money, I compute each advertiser's overcharge from the corrected counts, issue credits, let pacing resume from corrected spend so campaigns that stopped early can deliver again, and tell advertisers proactively, before they discover it themselves. For the future, the real problem was that six hours passed unnoticed.
So I add reconciliation every hour against an independent count, click-server logs or a parallel batch job, with alerts per ad format, because a doubled small format barely moves the total. Changes to aggregation logic run in shadow next to production, and we compare outputs before switching.
And raw events are kept at least as long as the longest detection and correction window plus the billing dispute period, which usually means months, because they are the only evidence that makes a repair exact instead of guesswork.
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 "How do you correct the data and the money, and how should the aggregation system be...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/4dcaacfc0d/