System Design
Ad Click Aggregator
Design a real-time ad click aggregation system.
Functional requirements
- Ingest ad click events from web and mobile clients (each event carries ad_id, user_id, timestamp, IP, and metadata).
- Serve the number of clicks for a given ad_id over the last M minutes, aggregated in 1-minute windows.
- Serve the top-K most-clicked ads over a configurable window (e.g., top 100 ads in the last 1 hour).
- Support filtering aggregations by dimensions such as country and device type.
- Detect and exclude fraudulent/duplicate clicks (e.g., the same user rapidly clicking the same ad) from billed counts.
- Aggregated metrics are consumed via advertiser-facing dashboards/APIs, i.e., advertisers query the performance of their own ads.
Non-functional requirements
- Aggregated counts must be correct for billing purposes: exactly-once semantics end-to-end (no double-counting, no lost clicks), even across failures and retries.
- End-to-end freshness: a click should be reflected in query results within ~1 minute; query latency for dashboards under 500ms p99.
- High availability for the ingestion path: dropping click events means dropping revenue; prefer buffering/degraded freshness over data loss.
- Durability: raw click events must be retained so aggregates can be recomputed/audited if a bug or dispute is discovered.
- Handle late-arriving events (mobile clients may deliver clicks minutes late) and traffic spikes during major live events.
Scaling & constraints
- 1 billion clicks per day on average, spread across roughly 2 million active ads.
- Peak traffic during live events can reach 5x the average rate, concentrated on a small set of hot ads.
- Each click event is roughly 0.1 KB.
- Read (analytics query) to write (click) ratio is roughly 1:200, meaning this system is heavily write-dominated.
- Raw events must be retained for 1 year for auditing; aggregated data retained for 3 years.
- Up to ~2% of events may arrive more than 1 minute late; a small fraction arrive up to several hours late.
Out of scope
- Ad serving, targeting, and auction/bidding logic.
- The actual billing/invoicing pipeline that consumes the counts.
- ML-based fraud models: a simple rule-based dedup/fraud filter is sufficient.
- GDPR/data-deletion workflows for user data.
Sign in to save your progress
AI design evaluation
Get a grounded score, what your design does well, its gaps, and what to study next.
Sign in to get AI feedback on your design.