Ad Ranking & CTR Prediction
Ad systems are the single largest revenue source for most consumer internet platforms. Google, Meta, Pinterest, and Instacart each run recommender systems, but their "items" are ads with bids, budgets, and auction rules layered on top. The ML challenge: predict the probability that a user clicks an ad (CTR), then combine that prediction with the advertiser's bid into a fair ranking that maximizes both relevance and revenue.
Real-world examples: Pinterest's CTR model, Criteo's personalized ad delivery (204 billion daily ad impressions), Instacart's sponsored product ranking, Grab's taxi surge & promotions, Duolingo's ad unit relevance, Autotrader's dealer ad auctions.
The ad ranking objective
In most ad auctions, ads are ranked by expected revenue, not raw bid:
where eCPM is the estimated cost per thousand impressions. A cheaper ad with a very high predicted click probability outranks an expensive ad with poor relevance. This alignment of ML quality and revenue is the key design principle: better CTR prediction directly increases auction revenue.
Predicting CTR: feature interactions
CTR prediction is a structured tabular problem with very high-cardinality categorical features: user ID (millions), item ID (millions), publisher ID (thousands), hour of day, device type, query. The key is modeling feature interactions — the CTR for "Nike shoes ad" shown to "runner user" during "morning" is much higher than any single feature predicts.
Wide & Deep Learning
Google's Wide & Deep (2016) architecture:
- Wide component: memorizes frequent co-occurrence patterns with a linear model over manually crafted crossed features. Fast, interpretable, captures known interactions.
- Deep component: generalizes via embeddings → MLP. Discovers unseen interaction patterns.
Still widely deployed — the "wide" side prevents the MLP from forgetting proven patterns.
DeepFM
Replaces the hand-crafted wide component with a Factorization Machine (FM) that automatically models all pairwise feature interactions via embedding dot products:
The FM and MLP share the same embedding table, so second-order interactions learned by the FM and higher-order patterns learned by the MLP reinforce each other. DeepFM is the standard baseline for CTR prediction on public benchmarks (Criteo display ads dataset).
DLRM (Deep Learning Recommendation Model)
Meta's architecture (used in production for Facebook ads): a dedicated interaction layer that explicitly computes the dot product of every pair of embedding vectors and concatenates with dense features:
This makes cross-feature interactions explicit and keeps the memory footprint manageable by sharing embedding tables across features. DLRM runs at billions of samples per day on thousands of GPU/CPU nodes.
Why embedding-based models beat tree models on CTR
GBDT handles tabular features well but requires explicit feature crosses. For ad CTR with millions of IDs, you can't enumerate all crosses — the embedding lookup + FM/MLP learns them automatically. In practice, an XGBoost model stacked on DLRM embeddings often outperforms either alone.
The auction mechanism
Second-price (Vickrey) auction
The dominant mechanism in online advertising. Advertisers submit bids; the winner is the highest bidder but pays only the second-highest bid (plus a small increment):
Why second-price? It is truthful — each advertiser's dominant strategy is to bid their true willingness to pay, regardless of what others bid. This simplifies auction dynamics and improves revenue predictability.
Generalized Second Price (GSP) auction
Used by Google Ads and most search ad systems: multiple ad slots ranked by bid score, each slot winner pays the bid score of the next slot below them. Not perfectly truthful (unlike VCG), but computationally simpler and practically stable.
Reserve prices and floors
Platforms set a reserve price — a minimum bid below which an ad isn't shown even if it wins the auction. Reserve prices prevent low-value ads from cluttering premium inventory and establish a floor on publisher revenue.
Budget constraints and pacing
An advertiser bids per click but has a daily budget. Without pacing, the budget could exhaust in the first hour. Budget pacing throttles ad delivery to spread spend evenly:
- Soft pacing: reduce the bid by a throttle factor based on current spend vs plan: .
- Hard throttling: probabilistically skip auction entry to match a target impression rate.
LinkedIn's pacing system uses a proportional-integral controller to compute , treating daily budget as the setpoint and current spend rate as the process variable.
Calibration: from score to probability
A CTR model trained with logistic loss produces a score that is monotonically consistent with click probability but not necessarily calibrated (i.e., a score of 0.7 does not mean 70% click rate). Auction eCPM math assumes the score is a true probability.
Platt scaling: fit a logistic regression on the model's output score against true click labels on a held-out calibration set. After calibration, is a well-calibrated probability.
Positional bias invalidates raw CTR estimates
Ads in position 1 get more clicks than ads in position 5, regardless of quality. If training data conflates position with inherent CTR, the model learns a spurious signal. The standard fix: include position as a feature at training time but set it to a fixed value (e.g., position 1) at serving time — a form of counterfactual debiasing.
The full pipeline
User request → Query features + User features
↓
Candidate retrieval (pre-filtered eligible ads)
↓
CTR model (DeepFM/DLRM) → predicted CTR
↓
eCPM = CTR × bid (paced)
↓
Auction (ranked by eCPM, second-price payment)
↓
Serve ranked ads → log click/no-click
↓
Feedback loop: retrain CTR model daily/hourly
Pinterest runs this pipeline at ~200 billion monthly ad impressions; Instacart's sponsored products system serves results in < 80 ms.
Exercise
Platform A ranks ads by raw bid. Platform B ranks ads by eCPM (predicted CTR × bid). Which platform earns more revenue per impression, and why?
Need a hint?
Consider what happens when a highly relevant but lower-bidding ad competes with an irrelevant high bidder.
Exercise
In a second-price auction, advertiser A bids $5, B bids $3, C bids $2. What does the winner pay?
Need a hint?
Second-price means the winner pays the next-highest bid.
Exercise
DeepFM combines a Factorization Machine (FM) with an MLP. What specific advantage does the FM component provide over a plain MLP?
Need a hint?
Think about how the FM and MLP handle feature interactions differently.
Common mistakes
- Ranking by bid alone. Ignoring predicted CTR fills premium slots with irrelevant ads and destroys long-term revenue; rank by eCPM.
- Using uncalibrated scores in the auction. eCPM math assumes true probabilities; apply Platt scaling (or isotonic regression) before multiplying by bid.
- Training on position-confounded clicks. Include position as a training feature and freeze it at serving time, or the model learns "slot 1 is clickable" instead of ad quality.
Key takeaways
- Ads are ranked by eCPM = predicted CTR × bid, aligning ML quality with platform revenue.
- DeepFM / DLRM learn feature interactions automatically via embedding dot products — essential for high-cardinality ID features.
- Second-price auctions are the standard mechanism; they are truthful, so advertisers bid their true value.
- Budget pacing distributes spend over time; calibration ensures CTR scores are true probabilities for correct eCPM math.
Related concepts
- Deep & Two-Tower Recommenders: the same retrieval funnel that candidate ads come through
- Logistic Regression: the output head of every CTR model
- Calibration & Uncertainty: why raw model scores need calibration before use in auctions