KatInterview

Ad serving platform with experiment assignment and tracking

System DesignModel answer
MediumModel answerSystem Designad-techexperimentationhigh-throughput

Last updated

Build a system that delivers targeted ads with low latency, tracks engagement events, and supports deterministic A/B test assignment and analysis.

You're designing a platform that serves advertisements to users and supports running controlled experiments on ranking logic and creative variations.

What the system does

When a user opens an app or webpage, the client requests an ad for a specific slot (e.g., a banner at the top of the screen). Your system selects an appropriate ad from available inventory and returns metadata the client uses to display it. Users may then see the ad (impression) or interact with it (click), and those events must be captured for reporting and billing.

What you need to support

Core functionality

  • Store and manage ad campaigns and their associated creatives (images, videos, etc.)
  • Target ads based on attributes like geography, device type, app section, and optionally user interests
  • Choose which ad to show for each incoming request
  • Record impressions (ad was displayed) and clicks (user interacted)
  • Enforce at least one delivery rule: budget limits with spend pacing, per-user frequency caps to avoid showing the same ad too often, or deduplication of events

Experimentation

  • Run tests that modify selection algorithms or swap in different creatives
  • Assign users to experiment groups in a stable, repeatable way
  • Capture which experiments and variants each user saw
  • Compute metrics like click-through rate per variant for analysis

Performance and reliability

  • Respond to ad requests in tens of milliseconds (p99 target around 50 ms for the decision, not including asset download from CDN)
  • Handle high request volume (assume millions to tens of millions of requests per day, with peak traffic 5–10× the average)
  • Stay available even when parts of the system fail
  • Clarify which data must be real-time versus eventually consistent (e.g., dashboards can lag by minutes, but budget enforcement needs to be current within seconds)

What to cover in your design

  1. Architecture overview: main services and how they interact
  2. Data modeling: how you store campaigns, targeting rules, and event logs; which databases or storage systems you choose and why
  3. Request flow: step-by-step path from client request to ad selection to response, including any caching strategies
  4. Event pipeline: how impression and click events flow through the system, get deduplicated, and land in reporting stores
  5. Experiment infrastructure: how assignment works, how you log exposures, how metrics are computed, and what safety mechanisms (guardrails) you'd include
  6. Trade-offs and failure handling: key decisions you made, what breaks under load or partial failure, and how you'd mitigate it

Assume you're not building a real-time bidding exchange with external demand partners—keep the scope to an internal ad server with a known set of campaigns.

Hints

Hint 1

Start by estimating request and event volumes in queries per second and daily storage to anchor your choices

Hint 2

Keep the ad catalog (campaigns and targeting rules) small enough to fit in memory on each server—this is the key to hitting latency goals

Hint 3

Use deterministic hashing on a stable user identifier for experiment assignment so the same user always sees the same variant without requiring a lookup

Hint 4

Separate real-time enforcement (frequency caps, budget checks) from batch analytics (billing reconciliation, final experiment reports) to balance accuracy and speed