ML System Design · ML Systems Lab

Ads CTR Prediction: The Full System Behind Every Ad You See

Ads CTR prediction is one of the highest-impact ML systems ever built — it generates the majority of revenue for Google, Meta, and ByteDance. The model must score billions of (ad, user, context) triples per day in milliseconds, stay calibrated as user behaviour shifts, and handle an extreme class imbalance (1 click per 100 impressions is high CTR). This is the full system: features, model architecture, training, calibration, and auction.

Click-Through Rate prediction is the core ML problem of the ads industry. The model answers: given this user, this ad, and this context, what is the probability that the user clicks? The answer feeds the ad auction — which ad wins, at what price. A 0.1% improvement in CTR prediction accuracy translates to tens of millions of dollars in annual revenue at scale.

Why CTR prediction is hard

Scale: Google processes 8.5 billion searches per day. Each produces an auction with multiple candidate ads. Each auction requires CTR predictions for all candidates. The model must run in < 10ms per auction at billion-query-per-day scale. Class imbalance: a 2% CTR is excellent. The model trains on data that is 98% negative (no click). Rare positive signals are swamped by negatives. Sparse features: user IDs, ad IDs, and keyword IDs are one-hot encoded over vocabularies of hundreds of millions. Feature interactions matter enormously: "user who recently searched for hiking boots" × "ad for outdoor gear" → high CTR, but neither feature alone predicts much.

Feature engineering

User features: historical CTR for this user, recent search queries (as embeddings), demographic signals (age, gender, location — where available and permitted), device type, time since last click. Ad features: ad ID embedding, advertiser category, ad text embedding, historical CTR (overall and by segment), bid amount. Context features: query text embedding, page type, position (above-the-fold vs below), time of day. Interaction features: cosine similarity between user query embedding and ad text embedding, user's historical CTR for this advertiser category.

The FTRL-Proximal algorithm: online learning for ads

Ads models cannot be trained once and deployed — user behaviour, advertiser bids, and trending topics shift daily. Follow-The-Regularised-Leader with Proximal gradient (FTRL-Proximal, McMahan et al. 2013) is the industry standard for online learning at ads scale. It is an online gradient descent algorithm with per-coordinate learning rates (like Adam, but adaptive across millions of sparse features) and L1 regularisation to maintain sparsity. FTRL processes each impression immediately after the click outcome is known (typically with a delay of minutes to hours) and updates the model continuously. This allows the model to adapt to distribution shift without full retraining.

Deep learning for CTR: Wide & Deep and DeepFM

Wide & Deep (Cheng et al., Google Play, 2016): a wide linear model handles memorisation (learning specific feature interactions observed in training data, e.g., "user installed this game before is correlated with installing similar games"), while a deep neural network handles generalisation (learning abstract features from raw inputs). The outputs are summed and passed through a sigmoid. This architecture dominated app store recommendation from 2016-2020.

DeepFM (Guo et al., 2017): replaces the wide component with a Factorisation Machine (FM), which explicitly models pairwise feature interactions via inner products of embedding vectors. FM captures cross-feature interactions without engineering them manually. DeepFM jointly trains FM and a deep network end-to-end. DCN (Deep & Cross Network, Wang et al., 2017) adds an explicit cross network for high-order feature interactions. These architectures are the current backbone of ads CTR at Alibaba, Tencent, and Bytedance.

The Vickrey auction: pricing the click

Ads are sold in a Vickrey (second-price) auction: the winner pays the minimum bid needed to win (the second-highest bid), not their own bid. The winning ad is not the highest bidder — it is the highest effective bid: eCPM = bid × predicted_CTR. A lower-bidding but more relevant ad can beat a higher-bidding but irrelevant one. This aligns advertiser incentives (bid your true value) with user experience (serve relevant ads).

Calibration is critical for auction integrity

The auction relies on P(click) being a true probability, not just a ranking score. If the model's P(click) = 0.05 but the true CTR is 0.02, the auction systematically overcharges advertisers, under-delivers on campaign objectives, and misranks ads relative to their true value. Calibration (see Post 76) must be continuously monitored. Both Platt scaling and temperature scaling are used to keep the model outputs calibrated as data distribution shifts.

Try on Colab: use the Criteo Display Advertising dataset (45M impressions, 13 numerical + 26 categorical features). Train a logistic regression baseline with FTRL (implement with per-coordinate learning rates). Then train a DeepFM using PyTorch. Compare AUC and log-loss. Apply temperature scaling and compare ECE before and after. Plot the reliability diagram.

Continue interactively
Read this post inside ML Systems Lab — with Simplify toggle, interview Q&As, inline glossary, and the MLE Path forward pointer.
Open in MSL →