Design ad click infrastructure
The question
Design the ingest and attribution path for ad clicks at high volume. Cover how a click is joined to the impression that preceded it, what happens when the click arrives hours later, and how you count exactly once when a client retries. Then discuss where fraudulent click patterns get detected without adding latency to the serving path.
Draft write-up. The title is what was reported. Everything below it was written by us to flesh the question out, so treat the specifics as illustrative rather than as the interviewer’s words.
What's being tested
Whether you can design a join across a window far wider than any buffer you would want to hold in memory, and stay honest about what gets counted twice or dropped when the two sides disagree.
Clarify first
- How long is the attribution window — minutes, or days?
- Does billing run off this pipeline, or is it advertiser-facing reporting only?
- Is a click without a matching impression discarded, or held?
- Real-time dashboards, or is batch latency acceptable?
A concrete version
Something like a million impressions a second and clicks three orders of magnitude rarer, with an attribution window of 24 hours. Buffering a day of impressions in memory is not an option, so the join has to reach into storage.
Structuring an answer
- 01Log impressions and clicks to separate append-only streams, each keyed by an id minted at serve time.
- 02Carry the impression id in the click, so attribution is a lookup rather than a heuristic match.
- 03Do the join in two tiers: a hot store for the recent window, then a batch reconciliation pass that catches late arrivals.
- 04Deduplicate on a client-supplied idempotency key so retries collapse.
- 05Publish counts twice — a fast approximate number for dashboards, and a reconciled number for billing — and make the difference explicit.
An outline, not a model answer. Interviewers are listening for how you reason, so working through it yourself beats reciting this.
Follow-ups
- A click arrives whose impression id was never logged. Count it, drop it, or quarantine it?
- How do you correct a number already shown to an advertiser?
- Where does fraud detection sit so it does not add latency to serving?
Common mistakes
- Joining on user id plus a timestamp guess instead of carrying an explicit impression id.
- Promising exactly-once end to end without saying where the deduplication actually happens.
- Serving one number for both dashboards and billing, then having no story when they diverge.
1 person reported this question. One more independent report moves it to corroborated.
I was asked this too