Design an Ad Click Aggregator for Advertiser Click Reporting
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
Design an ad click aggregator. When a user clicks an ad, the system records the click and sends the user on to the advertiser's landing page. It aggregates the recorded clicks so that advertisers can see how many clicks each of their ads received over a chosen time range, for example minute by minute. The report gives only the name of the problem, so scale, freshness and accuracy requirements are open: settle them with the interviewer before designing.
```hint Separate the click from the count
Think about what must happen while the user waits for the redirect, and what can happen afterwards from a durable record of the click.
```
```hint Counting under replays
Ask what happens to a stored count when the same click event is processed twice after a crash, or arrives minutes after the window it belongs to.
```
### Clarifying Questions
- How many clicks per second arrive on average and at peak, and how many ads are active?
- Which queries must advertisers run: counts per ad over a time range, totals per campaign, top ads, other breakdowns?
- How fresh must the numbers be, and how long must raw clicks and aggregates be kept?
- Are the counts used for billing, so that they must be exactly right and auditable, or only for monitoring dashboards?
- Must repeated or fraudulent clicks be excluded, and how late can a click event arrive?
### What a Strong Answer Covers
- Functional and non-functional requirements and scale estimates agreed before the design
- A click path that records every click durably and redirects quickly, without depending on the analytics pipeline
- Stream aggregation: partitioning by ad, event-time windows, watermarks and late events
- Exactly-once or idempotent counting, with deduplication of repeated clicks
- A storage and query layer suited to time-range queries per ad, with roll-ups for long ranges
- Reconciliation against raw events when counts drive billing, plus hot-ad skew, failure recovery and monitoring
### Follow-up Questions
- One ad goes viral and receives a large share of all clicks. How do you keep its partition from becoming a bottleneck?
- The stream processor crashes and restarts from its last checkpoint. How do you avoid counting clicks twice?
- A bug inflated the stored counts for several hours. How do you correct them?
- How would you detect and exclude click fraud, such as one device clicking the same ad again and again?
Overview: Design an ad click aggregation system that records every ad click, redirects the user to the advertiser, and lets advertisers query click counts per ad over time ranges. It probes stream processing, event-time windows, deduplication, exactly-once counting, hot-ad skew and reconciliation when the counts drive billing.
Read the full Meta Software Engineer interview experience this question came from