How would you design the click-through rate prediction system for an ads platform?
Written by the mlprep team · Updated
Design the system that predicts the probability a user clicks an ad, for an ads platform serving billions of impressions a day. Walk me through the data, features, model, and how the prediction is used.
How to drive the interview#
Clarify how predictions are used before designing the model:
- Is this cost-per-click advertising, where ads are ranked by expected value, roughly pCTR × bid?
- Latency budget per ad request, and how many candidate ads are scored per request?
- Are we predicting clicks only, or also conversions after the click?
- How fast does inventory turn over: new campaigns, new creatives, new advertisers?
That first question drives everything: because pCTR is multiplied by a bid and used for pricing, the model must output calibrated probabilities, not just a good ordering.
- Candidate ads targeting and budget filters select eligible campaigns
- Feature lookup user, ad, advertiser, and context features from the online feature store
- CTR model predicts a calibrated click probability for each candidate
- Auction rank by pCTR × bid (plus quality terms); price and select winners
- Logging impressions, clicks, and the exact features used, for training
Training data#
Each served impression is an example; a click within an attribution window is the positive label. Log the features exactly as they were at serving time and join clicks to impressions later. Recomputing features after the fact is a classic source of train/serve skew.
Two biases to name:
- Selection bias: you only observe clicks on ads the current system chose to show. Some exploration traffic, or logging propensities, helps the next model learn about ads the current one undervalues.
- Position bias: ads in higher slots get more clicks regardless of quality. Include position as a training feature and set it to a fixed value at serving time, or model it separately.
Features#
- User: historical CTR by category, recent interests, device, coarse location.
- Ad and advertiser: creative format, landing page category, historical CTR of the ad, campaign, and advertiser, smoothed toward priors for new ones.
- Context: placement, time of day, page or query content.
- Crosses: user interest × ad category, query × ad keyword. Interactions carry much of the signal in ads.
Most features are high-cardinality IDs. Represent them with learned embeddings or the hashing trick rather than one-hot vectors over billions of values.
Model#
A common progression:
- Logistic regression with hashed feature crosses: fast, naturally well-calibrated, easy to update online. Still a strong baseline.
- GBDT features feeding a linear model: trees learn interactions automatically.
- Deep models with embeddings and explicit interaction layers (Wide & Deep, DCN, DLRM-style): learn crosses from data, handle sparse IDs through embeddings, and are the norm at large scale.
The choice is bounded by serving cost. The model runs on every candidate ad for every request, so a few milliseconds per batch of candidates matters.
Your new model has better AUC offline, but advertisers' costs jumped and revenue moved unexpectedly after launch. What happened?
Calibration is a product requirement#
AUC is invariant to any monotonic transformation of the scores, so a model can improve AUC while its probabilities drift away from the true click rates. In an ads system that shows up directly in money:
- Overpredicted CTR inflates expected value, which changes which ads win and how they are priced, so advertisers are charged in ways that don't match real performance.
- Miscalibration that varies by segment (new ads, certain placements) shifts spend between advertisers unfairly.
What to measure#
- Log loss (and normalized entropy, log loss relative to a baseline that always predicts the average CTR): sensitive to calibration and discrimination.
- Calibration ratio: total predicted clicks / actual clicks, overall and by segment (placement, ad format, new vs established advertisers).
- AUC: still useful for ordering, but not sufficient on its own.
Fixing it#
- Post-hoc calibration on held-out recent data: isotonic regression or Platt scaling, possibly per segment.
- Recalibrate after changes that shift the score distribution: negative downsampling, new features, or a different loss.
- If you downsample negatives for training efficiency, correct the predicted probabilities for the sampling rate. Forgetting this is a common cause of systematic overprediction.
New ads launch every hour and user behavior shifts quickly. How do you keep the model fresh, and how do you handle clicks that arrive late?
Freshness#
Ads models lose accuracy quickly as inventory and behavior change, so freshness is a first-order lever:
- Retrain or incrementally update frequently, from daily batch jobs down to near-real-time online updates for the sparse embedding and linear parts.
- Warm-start from the previous model instead of training from scratch.
- For new ads, back off to advertiser-, campaign-, and category-level statistics with smoothing, and reserve some exploration traffic so new ads collect data.
Delayed feedback#
A click can arrive after the impression is logged. If you label an impression negative immediately and it later gets clicked, the model learns systematically low CTRs, and the bias is worst for the freshest data.
Options:
- Wait a fixed attribution window before finalizing labels; this trades freshness for correctness.
- Ingest the impression as a negative and then correct when the click arrives, using a loss or importance weighting designed for delayed feedback.
- Monitor the calibration ratio on the most recent data separately; delayed feedback problems show up there first.
Safe updates#
Frequent updates mean frequent chances to break something. Gate each new model on calibration and log loss against the current one, watch prediction distribution shifts in real time, and keep automatic rollback.
Interview red flags#
- Optimizing AUC alone without mentioning calibration, even though the prediction is multiplied by a bid.
- Downsampling negatives without correcting the predicted probabilities.
- Recomputing training features after the fact instead of logging them at serving time.
- Ignoring position bias and selection bias in logged data.
- A daily retrain with no plan for ads created since the last one.
Go deeper: Feature crosses covers interaction features; Calibration drift covers why calibration degrades after launch; Position bias covers correcting for slot effects.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Ads CTR prediction feeds an auction that multiplies pCTR by bids, so calibration is a hard requirement, not a nice-to-have. Log features at serving time, correct for position and selection bias, use embeddings and explicit crosses for sparse IDs, measure log loss and calibration by segment alongside AUC, correct probabilities after negative downsampling, retrain frequently with smoothed priors for new ads, and handle delayed clicks explicitly.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you extend this to predict conversions after the click, when conversions are rare and can arrive days later?
- How would you allocate exploration traffic to new ads without hurting short-term revenue too much?
- How would you detect and handle click fraud polluting your training labels?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
How would you design a recommendation system for Reddit?
How would you design Amazon's product search ranking system?
How would you design a feature store for a large ML platform?
What is model calibration and how do you fix a miscalibrated model?