Practice: Design Ad Serving System
Design an ad serving system that selects and delivers the most relevant ad for each impression within a strict latency budget. The system must manage campaign budgets, pacing, targeting, and attribution at scale. A teaching design inspired by real ad servers, not any one company's internal architecture.
Build this system yourself on the canvas below. Add components, connect them, and run traffic simulations to see where your design holds up and where it breaks.
Functional requirements
- Accept impression requests with user targeting context (geo, device, interests, page content).
- Select the highest-value ad based on bid price and relevance (CTR, conversion rate).
- Enforce per-campaign daily and hourly budgets; reject impressions if budget exhausted.
- Support real-time budget pacing: distribute daily budget evenly across 24 hours.
- Track impressions, clicks, and conversions for billing and performance reporting.
- Implement fraud detection: identify bot clicks, invalid traffic patterns, and suspicious CTRs.
- Support A/B testing and canary deployments for new ranking algorithms.
- Provide attribution modeling (last-click, multi-touch) for credit allocation to ads.
Non-functional requirements
- Latency: ad serving p99 < 50ms; real-time budget enforcement < 5ms overhead.
- Throughput: scale to billions of impressions per day (millions per second peak).
- Availability: 99.95%+; single AZ failure must not halt ad serving.
- Consistency: budget must never exceed daily limit across all servers.
- Fraud: detect invalid traffic within seconds; automatically quarantine suspicious campaigns.
- Scalability: horizontally scale ad servers, cache layer, and event processing independently.
- Observability: per-campaign metrics, p99 latency, budget consumption, fraud signals in real-time.