ML System Design

Design: Ad Click Prediction

Predicting whether a user will click a digital advertisement with calibrated probabilities for auction pricing.

🔴 advanced8 min readsystem-designads
Designing an Ad Click Prediction System requires predicting calibrated click probabilities for real-time ad auctions. The system must handle billions of daily impressions, sparse high-cardinality features, and strict latency requirements. Architecture involves candidate ad retrieval, a deep CTR model (DCNv2, DIN), probability calibration, and auction ranking by expected value.

The Problem

Design a system that predicts the probability a user will click a given ad. The system serves 50,000 queries per second. Each query must score hundreds of candidate ads in under 20ms. Predicted probabilities must be well-calibrated because they directly determine how much advertisers pay.

High-Level Architecture

  Ad Request (User visits page)
              │
              ▼
  ┌───────────────────────────────┐
  │ STAGE 1: AD CANDIDATE RETRIEVAL│  (~3ms)
  │ Targeting filters + ANN search │
  │ Output: ~200 Eligible Ads      │
  └───────────────────────────────┘
              │
              ▼
  ┌───────────────────────────────┐
  │ STAGE 2: CTR PREDICTION       │  (~10ms)
  │ Deep Model (DCNv2 / DIN)      │
  │ Output: pCTR for each ad      │
  └───────────────────────────────┘
              │
              ▼
  ┌───────────────────────────────┐
  │ STAGE 3: AUCTION RANKING      │  (~2ms)
  │ Score = pCTR × Bid Price      │
  │ Second-price auction rules    │
  │ Output: Winning ad(s)         │
  └───────────────────────────────┘

Stage 1: Ad Candidate Retrieval

Not all ads in the system are relevant. Filter candidates by:

This narrows millions of active ads down to a few hundred candidates.

Stage 2: CTR Prediction Model

The core model predicts $P(\text{Click} = 1 \mid \text{User}, \text{Ad}, \text{Context})$.

Features

Model Architecture

Industrial systems use architectures like:

Calibration

After training, check the reliability diagram. If predictions are not well-calibrated, apply Platt Scaling (fit a logistic regression on validation logits) or Isotonic Regression to align predicted probabilities with true click rates.

Stage 3: Auction

Rank ads by expected revenue:

$$\text{eCPM} = \text{pCTR} \times \text{Bid}_{\text{CPC}} \times 1000$$

The highest eCPM ad wins the slot. Under a Generalized Second-Price Auction, the winner pays just enough to beat the second-highest bidder, not their full bid.

Key Design Challenges

  1. Feature Sparsity: User IDs and Ad IDs have millions of unique values. Use embedding tables with hashing to handle this scale.
  2. Training Data Volume: Billions of impressions per day. Use online learning or frequent batch retraining.
  3. Serving Latency: Score hundreds of ads per request within 20ms. Use model distillation and TensorRT optimization.
  4. Click Fraud: Detect and filter bot clicks and click farms from training data to prevent poisoned models.

Say this out loud

An ad click prediction system retrieves candidate ads via targeting filters, scores each with a deep CTR model that produces calibrated probabilities, and ranks ads by expected revenue (pCTR times bid). Calibration is critical because predicted probabilities directly determine advertiser pricing in the auction.

Followups to expect

  1. What is delayed conversion attribution? A user may click an ad today and purchase 7 days later. The system must join click logs with conversion events using attribution windows to create proper training labels.
  2. How do you handle the cold start problem for new ads? Use exploration strategies (show new ads with boosted priority for initial impressions) and transfer learning from similar ads to estimate initial CTR.

Check yourself

Question 1 of 3

Why must ad click prediction models output calibrated probabilities rather than just correct rankings?

More in ML System Design

See all →
A Framework for Any ML Design Round5 minFraming a Business Problem as ML5 minOnline vs Offline Evaluation5 min