System Design
Design: Ads CTR Prediction
Learn Design: Ads CTR Prediction: 41 practice questions and answers with an interactive quiz — from the offline AI Learning app.
Questions & Answers
Tap a question to reveal its answer. Written for self-study and interview preparation.
What is the primary purpose of CTR calibration in ad serving systems?
CTR calibration ensures that a model's predicted click-through rate accurately reflects the true empirical probability of a click. Raw CTR prediction models trained with log-loss produce scores that rank ads correctly but may be systematically biased: a model predicting 0.05 CTR might correspond to a true empirical CTR of 0.03. Calibration fixes this bias. Why it matters: in a CPC (cost-per-click) auction, the ad rank is computed as bid × predicted_CTR. Miscalibrated CTR inflates or deflates the effective bid, distorting auction outcomes and revenue. Calibration methods: Platt scaling (sigmoid transformation on raw scores), isotonic regression (monotonic non-parametric function), temperature scaling (divide logits by a learned scalar). Evaluate calibration using the Expected Calibration Error (ECE) or Brier score. Re-calibrate whenever the model is retrained or the data distribution shifts significantly.
Design a CTR prediction system for a social media advertising platform with 500 million daily active users and 5 million active ads.
Requirements: sub-50ms scoring latency, accurate CTR prediction at massive scale, online learning to capture ad freshness. Pipeline: (1) Feature engineering—user features (age, interests, device, past ad interactions), ad features (creative type, category, landing page, historical CTR), context features (platform surface, time of day, user session stage); (2) Embedding tables—categorical feature embeddings (user ID, ad ID, advertiser) stored in distributed parameter servers; (3) Model—Wide & Deep: wide component for memorization (sparse feature products), deep component for generalization (dense MLP); or DeepFM for automated feature interactions; (4) Training—mini-batch SGD on a stream of click/non-click events from Kafka; update embeddings hourly; (5) Serving—exported to TorchServe with int8 quantization; feature lookup from Redis; (6) Calibration—isotonic regression layer applied post-prediction; (7) Online learning—lightweight adapter updated in near-real time; base model retrained daily. Metrics: AUC, log-loss, calibration error, revenue per query. Monitor: score distribution drift, ad CTR over time.
How does the Wide & Deep model improve CTR prediction compared to a pure deep learning model?
Pure deep learning (DNN) models with embedding layers are good at generalization—they find patterns in unseen feature combinations—but struggle with memorization of specific high-frequency feature interactions (e.g., 'user likes sports' AND 'ad category = sports equipment'). The Wide component is a linear model on manually engineered cross-product features; it directly memorizes these co-occurrence patterns with no generalization. The Deep component is a DNN on dense embeddings; it generalizes to unseen combinations. Wide & Deep trains both jointly with a shared loss. Result: the wide component captures actionable memorized rules while the deep component handles complex unseen patterns. In practice, the deep component contributes more to AUC improvement, but the wide component provides significant precision gains for high-frequency query-ad pairs. Introduced by Google for the Play Store recommendation (2016) and widely adopted in ads CTR systems. Pitfall: wide feature engineering requires domain expertise and manual feature cross selection.
How does DeepFM differ from Wide & Deep for CTR prediction?
DeepFM replaces the manually designed feature cross component in Wide & Deep with a Factorization Machine (FM) that automatically learns second-order feature interactions. Wide & Deep requires manual selection of which feature pairs to cross in the wide component—an expensive engineering effort that may miss important interactions. DeepFM shares the same embedding table between the FM component and the deep neural network, enabling the FM to learn pairwise interactions efficiently while the DNN learns higher-order interactions from the same embeddings. Result: DeepFM eliminates the need for manual feature engineering while matching or exceeding Wide & Deep accuracy. Comparison: FM captures all pairwise interactions; DNN captures high-order interactions; FM is more interpretable than DNN for understanding which feature pairs drive predictions. Variants: DCN (Deep & Cross Network) uses a cross network that explicitly models bounded-degree feature interactions more efficiently than FM. DeepFM is widely used in industrial CTR prediction at Huawei, JD.com, and Alibaba.
How does the Generalized Second Price (GSP) auction work in keyword advertising?
In GSP (Generalized Second Price) auctions used by search ad platforms (Google Ads), advertisers bid a maximum CPC for keywords. The auction ranks ads by bid × quality_score (where quality_score reflects predicted CTR and ad relevance). The top-ranked ad wins the first position but pays not its own bid—it pays the minimum amount necessary to maintain its rank, which is (next bidder's bid × next bidder's quality_score) / winner's quality_score + $0.01. This 'generalized second price' property reduces advertisers' incentive to shade bids dramatically below their true value. The quality score component means a highly relevant ad can outrank a higher-bidding but less relevant ad while paying less per click. Pitfall: GSP is not strategy-proof—unlike VCG, it incentivizes some bid manipulation. In practice, it is preferred over VCG because of simpler auction mechanics and easier advertiser understanding. CTR prediction quality directly affects quality score and therefore auction rank and revenue.
How do you handle the cold-start problem for new ads with no historical CTR data?
New ads have no impression or click history, making behavior-based CTR prediction impossible. Cold-start strategies: (1) Ad feature-based prediction—rely on ad content features: creative type, image quality score (ResNet aesthetic classifier), text sentiment, call-to-action presence, ad category, and landing page quality; a model trained on these content features predicts an initial CTR; (2) Advertiser history—inherit a prior CTR based on the advertiser's historical average CTR across all their past ads in the same category; (3) Similarity matching—find the K most similar ads in the historical catalog (by embedding similarity) and use their average CTR as the prior; (4) Exploration bonus—apply a UCB-style exploration bonus to new ads to ensure they receive impressions to accumulate data; Thompson sampling posterior updates after each impression; (5) Category priors—use the average CTR for ads in the same category, device type, and platform surface. Transition: gradually reduce the content-based prior and increase the behavior-based estimate as impression data accumulates (typically after 1000+ impressions). Monitor: new ad CTR convergence time as a platform health metric.
How do you build a multi-task learning system for CTR and conversion rate (CVR) prediction?
CTR and CVR are related but distinct tasks: a user must click before converting, creating a selection bias problem for CVR. Multi-task learning (MTL) addresses this. Architecture: ESMM (Entire Space Multi-task Model) from Alibaba models CTR and post-click conversion (CVR) as: pCTCVR = pCTR × pCVR, where pCTCVR (probability of click AND conversion) is observed on all impressions, not just clicks. This allows training CVR on the full impression space rather than only clicked samples, eliminating the sample selection bias. Implementation: (1) Shared embedding layer for user and item features; (2) Separate towers for CTR and CVR prediction; (3) Training objective: optimize pCTCVR (binary cross-entropy on all impressions) and pCTR (binary cross-entropy on all impressions) jointly; pCVR is implicit from the product; (4) Serving: output both pCTR and pCTCVR; use pCTCVR as the optimization target in ROI-based bidding. MTL variants: MMOE (Mixture of Experts) or PLE (Progressive Layered Extraction) for more complex objective combinations.
How do you handle the delayed feedback problem in conversion rate prediction?
Conversion events (purchases, sign-ups) arrive long after the click—minutes to days or weeks depending on the product. Training a CVR model on data from the last week produces a dataset where many recent conversions have not yet been observed, making recent clicks appear fraudulently as non-conversions. Solutions: (1) Fixed waiting window—only train on data older than the 90th percentile conversion delay; e.g., only use clicks older than 30 days to ensure nearly all conversions have been reported; fast to implement but wastes recent data; (2) Fake-negative correction—treat unobserved conversions as fake negatives; when a conversion arrives, add a correction example; weight examples by 1 / survival_probability at the observation time; (3) Survival analysis—model conversion probability using a hazard model (Weibull or Log-Normal) that explicitly accounts for censored (unobserved) conversions; (4) Online learning with delayed labels—use an online learning system that updates model weights when delayed labels arrive, weighted by a freshness decay factor. Monitor: calibration across different impression ages; fresh impressions should have calibrated lower CVR predictions.
What is the role of embedding tables in deep learning CTR models and how do you manage them at scale?
Categorical features in CTR prediction (user ID, ad ID, advertiser, query, publisher) are represented as learned dense embedding vectors rather than one-hot encodings. At the scale of billions of users and millions of ads, embedding tables become the largest component of the model—potentially terabytes. Management challenges: (1) Memory—embedding tables exceed single-machine RAM; distribute across a parameter server cluster with hash-based sharding; (2) Throughput—billions of embedding lookups per second require sharded servers with optimized RDMA communication; (3) Sparse updates—only a small fraction of embeddings are updated per training batch; use sparse gradient optimizers (Adagrad, SparseAdam) to update only touched embeddings; (4) Embedding compression—reduce dimension from 256 to 64 via SVD; use int8 quantization; use compositional embeddings for rare IDs; (5) Freshness—user and ad embeddings drift rapidly; refresh the embedding of new users and newly launched ads hourly; (6) ID collision—hash user IDs into a fixed embedding table size (hashing trick) to bound table size at the cost of some collision. Monitor: embedding table memory usage and lookup latency as primary infrastructure health metrics.
What is the key difference between CPC and CPM advertising models from an ML perspective?
CPC (Cost Per Click) advertisers pay only when a user clicks their ad; the platform revenue depends on click volume, so the platform optimizes for CTR. CPM (Cost Per Thousand Impressions) advertisers pay for every impression regardless of clicks; revenue is guaranteed per impression, so the platform optimizes for impression delivery to target audiences. ML implications: (1) CTR prediction importance—CPC auctions critically depend on accurate CTR prediction for both ad ranking (bid × CTR) and revenue projection; CPM auctions care less about CTR accuracy; (2) Targeting—CPM advertisers prefer audience targeting (demographic, interest-based) because they pay per impression and want reach; CPC advertisers prioritize intent-based targeting (keywords, behavioral signals) to maximize click probability; (3) Pacing—CPM campaigns must pace impressions evenly across the flight period; budget pacing models differ from CPC; (4) Mixed auctions—when CPC and CPM ads compete in the same auction, convert CPM bids to an effective CPM (eCPM = CPC_bid × predicted_CTR × 1000) for fair comparison. Most platforms run mixed auctions with eCPM normalization.
How does Deep & Cross Network (DCN-v2) improve feature interaction modeling for CTR prediction?
DCN-v2 (Deep & Cross Network v2, Google 2021) explicitly models bounded-degree polynomial feature interactions more efficiently than Wide & Deep or DeepFM. The cross network applies repeated cross transformations: x_{l+1} = x_0 ⊙ (W_l × x_l + b_l) + x_l, where x_0 is the original feature vector. Each layer adds one degree of interaction—after L layers, the network models up to L+1 order interactions. DCN-v2 uses a matrix formulation (replacing the vector formulation in DCN-v1) for richer, more expressive interactions. Architecture: cross network layers (explicit, structured interactions) run in parallel with DNN layers (implicit, unstructured interactions); outputs concatenated for a final prediction head. Advantages: fewer parameters than manually engineered feature crosses; captures interactions of all pairs automatically; outperforms DeepFM on Criteo and KDD benchmarks. Used at Google Search Ads and YouTube. Pitfall: cross network interactions are bounded-degree polynomial, potentially missing very high-order interactions captured by deep DNNs.
How do you design budget pacing for ad campaigns?
Budget pacing ensures an advertiser's daily budget is spent evenly throughout the day rather than exhausting it in the first hour. Without pacing, high-competition morning traffic depletes budgets before afternoon and evening audiences are served. Approaches: (1) Throttling—probabilistically enter auctions with probability p = remaining_budget / projected_remaining_spend; p is adjusted every 5–15 minutes via a feedback controller; (2) Bid shading—reduce the effective bid at times when the budget burn rate exceeds target; increase at slower periods; (3) Smoothing controller—model budget consumption as a PID controller; adjust throttling rate based on current spend rate vs target; (4) Predicted spend curves—predict hourly spend curves based on historical campaign data; allocate daily budget across hours accordingly; (5) Campaign priority—when budget is nearly exhausted, reduce throttling to avoid missing valuable conversion opportunities at end of day. Monitor: budget completion rate (fraction of campaigns that spend their full budget), over-delivery rate, and impression delivery uniformity. SLA: no campaign should deplete budget before 6pm for standard pacing.
How do you use look-alike modeling to expand advertiser audience targeting?
Look-alike modeling finds users who resemble an advertiser's known high-value customers (seed audience) to expand targeting reach. Architecture: (1) Seed audience definition—advertiser provides a list of their best customers (purchasers, high-LTV users) or the platform derives seeds from conversion pixel data; (2) Seed representation—compute the average embedding of all seed users in the platform's user embedding space; (3) Candidate scoring—score all platform users by their embedding similarity to the seed centroid (cosine similarity); (4) Calibration—map similarity scores to audience quality tiers (1%, 5%, 10% lookalike sizes); smaller lookalike audiences are more similar but smaller reach; (5) Model approach—train a binary classifier on (seed, non-seed) labels using user features; the classifier's output probability defines look-alike similarity; (6) Freshness—update lookalike scores weekly as user embeddings and seed audiences evolve. Privacy: compute look-alikes on anonymized user IDs; never expose individual user membership. Applications: prospecting campaigns (brand awareness), retargeting expansion (similar to converters). Evaluate with holdout lift test: compare conversion rate of look-alike targeted users vs random users.
How do you apply differential privacy to protect user data in ads CTR models?
Differential privacy (DP) provides mathematical guarantees that individual user data cannot be inferred from a trained model's outputs. Application to CTR models: (1) DP-SGD—add calibrated Gaussian noise to gradients during mini-batch training; clip gradient norm to sensitivity bound C; add noise scaled to C×sigma/batch_size; the privacy budget is tracked using the moments accountant; (2) Privacy budget allocation—allocate a total epsilon (privacy budget) across model training; smaller epsilon = stronger privacy but worse model utility; typical epsilon values in industry: 1–10; (3) Federated learning—compute gradients on-device and aggregate with secure aggregation and DP noise; useful when click data should not leave user devices; (4) Embedding table DP—apply DP to embedding updates, which carry more user-specific information than dense layer updates. Tradeoffs: DP degrades model AUC by 0.5–2%; disproportionately hurts rare user segments (long-tail users have fewer training samples, so noise dominates). Privacy amplification via subsampling reduces effective epsilon. Report privacy budget to users and regulators as part of a privacy policy.
How does exploration in ad auctions work to address the cold-start problem for new ads?
Without exploration, new ads with no CTR history are predicted to have low CTR, rank low in auctions, receive few impressions, and never accumulate data—a permanent cold-start loop. Exploration strategies: (1) Thompson sampling—maintain a Beta(alpha, beta) prior for each ad's CTR (alpha = clicks + 1, beta = impressions - clicks + 1); sample a CTR draw from the posterior at each auction; high-uncertainty new ads have high posterior variance and will occasionally win auctions; (2) UCB bonus—add an uncertainty bonus to the predicted CTR: score = predicted_CTR + c × sqrt(1 / impressions); (3) Epsilon-greedy exploration—with probability epsilon, randomly boost a new ad's bid to win an impression; (4) Randomized exploration traffic—reserve a small percentage of auction impressions for pure exploration (random ad selection) independent of bid and CTR prediction; use these impressions to build initial CTR estimates. Tradeoffs: exploration reduces short-term revenue (non-optimal ads win impressions); necessary for long-term platform health and advertiser retention. Monitor: new ad time-to-first-100-impressions as a platform health metric.
How do you engineer contextual features for CTR prediction?
Contextual features capture the serving context at impression time and are critical for CTR accuracy. Key contextual features: (1) Platform surface—app vs web, news feed vs search results page, story vs in-stream; CTR varies dramatically by surface; (2) Device type—mobile, tablet, desktop; mobile users show different CTR patterns and have shorter sessions; (3) Time features—hour of day (sin/cos encoding for cyclical nature), day of week, is_weekend, is_holiday; engagement patterns are highly temporal; (4) Geographic context—country, city-level; ad relevance varies by region; (5) User session context—position in session (early session vs late session), time since last click, number of ads seen in current session; (6) Query context—for search ads, query keywords, query intent category, user search history in the session; (7) Page context—surrounding organic content category, scroll depth at which the ad appears. Combine contextual features with user and ad features via feature crossing and embedding lookups. Pitfall: contextual features change at every impression—ensure they are fresh and served from a low-latency context service, not fetched from a slow database at inference time.
How do you detect and mitigate click fraud in ad systems?
Click fraud involves generating fake clicks on ads to deplete competitors' budgets or earn fraudulent publisher revenue. Detection signals: (1) Abnormal click patterns—bot-like click velocity (many clicks in a short time), regular inter-click intervals, unusual time-of-day patterns; (2) IP analysis—high click volume from single IPs or IP ranges; data center IP blocks without residential traffic; (3) Device fingerprinting—same device generating clicks across many different advertisers' ads; (4) Session analysis—clicks without corresponding page loads or zero conversion rate from a source; extremely short post-click session durations; (5) Publisher fraud—one publisher's inventory showing disproportionate clicks with no conversions; compare click-to-conversion ratio by publisher against category baseline. ML approach: train a binary classifier on (fraudulent click, legitimate click) labels using the above features; apply in real time to reject suspicious clicks before billing. Infrastructure: integrate with third-party fraud detection APIs (IAS, DoubleVerify). Refund policy: advertisers receive credits for detected invalid clicks. Monitor: invalid click rate by publisher, advertiser complaint rate, and fraud analysis audit.
How do you optimize an ad serving system for revenue per query (RPQ)?
Revenue per query (RPQ) measures total revenue generated per search or page view. Maximizing RPQ requires jointly optimizing ad relevance (CTR), bid price, and auction efficiency. Optimization levers: (1) Better CTR prediction—higher CTR predictions for relevant ads increase their effective bid (eCPM = bid × CTR), surfacing better ads and generating more clicks; (2) Auction mechanism tuning—reserve price optimization (minimum bid that must be exceeded for an ad to show) prevents low-value ads from winning at near-zero revenue; (3) Ad quality scoring—combine CTR, CVR, landing page quality, and ad experience in a quality score that affects ad rank; better quality ads earn higher placements for the same bid; (4) Number of ads shown—dynamically adjust the number of ads shown per query based on query commercial intent; non-commercial queries should show fewer or no ads; (5) Position value modeling—quantify the marginal RPQ contribution of each additional ad position; optimize the number of positions shown per query to maximize total RPQ. Monitor: RPQ by query type, market, device, and time of day. Alert on RPQ drops exceeding 3% from the 7-day baseline.
How do you evaluate CTR prediction model quality in production?
Offline and online evaluation serve different purposes. Offline evaluation: (1) AUC-ROC—measures ranking quality across all thresholds; target >0.75 for CTR; less sensitive to calibration; (2) Log-loss (cross-entropy)—measures probabilistic accuracy; sensitive to calibration; lower is better; (3) Calibration metrics—ECE (Expected Calibration Error), reliability diagrams; verify that predicted 5% CTR really occurs 5% of the time; (4) Normalized Cross-Entropy (NCE)—log-loss divided by log-loss of a simple prior; removes background CTR rate to measure model's added value; target NCE < 1 (better than prior). Online evaluation via A/B test: (1) CTR lift—fraction improvement in raw click rate vs control; (2) Revenue per query—critical business metric; (3) Conversion rate—downstream business impact; (4) User experience—ad relevance score (from user surveys or engagement signal), frequency of negative feedback (hide ad, report ad). Pitfall: improving offline AUC does not guarantee online metric improvement due to distribution shift and novelty effects. Always run online A/B tests before deploying a new CTR model.
How does frequency capping improve ad effectiveness and user experience?
Frequency capping limits how many times a single user sees the same ad within a defined time window, preventing overexposure. Benefits: (1) User experience—repeated exposure to the same ad causes annoyance and negative brand associations; research shows optimal frequency for brand awareness is 3–7 exposures; (2) Advertiser ROI—impressions beyond the effective frequency have diminishing and eventually negative returns on brand lift and conversion; (3) Inventory efficiency—freed impressions can serve other advertisers, increasing platform revenue diversity. Implementation: (1) Frequency counter—maintain a per-user, per-ad impression count in a low-latency key-value store (Redis) with TTL matching the frequency window (24h, 7d); (2) Auction filter—before evaluating each ad in the auction, check if the user's frequency for that ad exceeds the cap; exclude capped ads from the auction; (3) Dynamic frequency management—for high-value conversion campaigns, allow higher frequency; for brand awareness campaigns, apply stricter caps; (4) Cross-device frequency—deduplicate frequency across devices for logged-in users using a unified user ID. Pitfall: frequency cap bypass by identity graph limitations (privacy changes, iOS ATT) means caps are under-enforced for users without a unified ID.
What is the VCG (Vickrey-Clarke-Groves) auction mechanism and when is it used in advertising?
VCG is a generalized second-price auction mechanism that is theoretically strategy-proof: each bidder's dominant strategy is to bid their true value. In a multi-slot VCG auction, each bidder is charged the externality they impose on other bidders—the total value other winners would have received in the absence of this bidder, minus what they actually receive. Result: bidding true value maximizes each advertiser's expected surplus, regardless of other bidders' strategies. VCG is used in some display advertising platforms but is less common than GSP in search advertising. Reasons: (1) VCG payments are more complex to explain to advertisers; (2) VCG revenue can be lower than GSP when bidders underbid (though strategy-proof theoretically); (3) VCG does not account for quality scores naturally. Ad relevance integration: VCG with quality adjustment multiplies true values by quality scores before running the externality computation. CTR prediction accuracy matters in VCG because quality scores affect the computed externalities and resulting prices.
How do you build a real-time feature pipeline for ads CTR inference?
CTR inference at ad serving time (within a 50ms SLA) requires all features to be available immediately. Real-time feature pipeline: (1) Request-time features—user agent parsing, geolocation resolution, timestamp decomposition computed at the serving layer with zero additional calls; (2) Online feature store—pre-computed user features (historical CTR, interest embeddings, category affinity) served from Redis with sub-5ms p99 latency; (3) Ad features—pre-computed and cached in memory at the ad server on daily model update; includes ad embedding, creative type, historical CTR; (4) Context assembly—aggregate features from all sources within a single gRPC call to a feature serving gateway; timeout: 10ms; fallback to default values on store timeouts; (5) Streaming feature updates—Flink job processes click and impression events from Kafka; updates user activity counters in Redis within 30 seconds of each event; (6) Schema consistency—validate feature schema against model expectations at serving time to catch training-serving skew. Monitor: feature serving latency p50/p99, feature freshness (age of last update for each user), and feature availability (fraction of requests with all features populated).
How do contextual advertising and behavioral targeting differ in CTR modeling?
Contextual advertising matches ads to the content of the page or query being viewed, without using user behavioral history. Behavioral targeting matches ads to individual users based on their browsing, purchase, and engagement history across the platform. CTR modeling differences: (1) Contextual signals—page topic, query keywords, article category, current session intent; requires no historical user data; GDPR-compliant by default; effective for intent-aligned queries (search ads); (2) Behavioral signals—user interest embeddings, past ad interactions, purchase categories, demographic inferences from behavior; requires user tracking and consent; more personalized but raises privacy concerns; (3) Model architecture—contextual models have lower feature dimensionality and simpler embedding tables; behavioral models require large user embedding tables; (4) Privacy regulations—iOS ATT and cookie deprecation have shifted industry focus back to contextual signals for third-party inventory. Current best practice: hybrid approach using contextual signals for all users plus behavioral signals for consenting users. Monitor: CTR and conversion lift separately for contextual-only vs contextual+behavioral targeting groups.
How do you apply online learning to keep a CTR model fresh in the presence of rapid ad content changes?
Ad catalogs change rapidly: new ads are created, campaigns are modified, and user behavior responds to external events. Batch-trained models go stale within hours. Online learning architecture: (1) Streaming training—process click and impression events from a Kafka stream; compute mini-batch gradients over a sliding window; update model weights every few minutes; (2) Learning rate scheduling—use a higher learning rate for embedding layers (faster adaptation) and lower rate for dense layers (prevent catastrophic forgetting); (3) Two-speed model—stable base model retrained nightly on 30 days of data; lightweight online adapter (small MLP or linear model) trained on the last few hours of data; combine both at inference: final_CTR = base_model × online_adapter_correction; (4) Feature store freshness—ensure the feature store reflects the latest user activity within 30 seconds; (5) Shadow serving—run online-trained model in shadow alongside the base model; promote when online metrics consistently improve. Pitfall: online learning on sparse events (rare ad categories) causes high variance updates; apply gradient clipping and minimum batch size constraints. Monitor: time-to-adapt (how quickly the model recovers after a major external event like a product launch).
How does native advertising affect CTR model design compared to banner ads?
Native ads blend into the host platform's content format (sponsored posts in a social feed, recommended articles in a content site), while banner ads are visually distinct. CTR modeling differences: (1) Higher baseline CTR—native ads typically achieve 3–5x higher CTR than banner ads because they are less visually jarring; calibration must handle this difference if models are shared; (2) Content relevance features are critical—native ad relevance to surrounding content (content-ad cosine similarity) is a stronger CTR predictor than for banners; (3) Creative format features—headline sentiment, article-style formatting, image type, presence of a brand logo; native ad creative quality matters more to CTR than banner creative; (4) Disclosure impact—'Sponsored' label position and visibility affects CTR; model should include disclosure format as a feature; (5) Session context—native ads perform differently depending on where in the content session they appear (early, mid, end); (6) Trust signals—user trust in the host platform significantly affects native ad CTR; model platform trust score as a context feature. Train separate models or use a model conditioned on ad format type.
How do you build an ad auction system that handles hundreds of thousands of transactions per second?
Ad auction systems must process impressions in under 100ms end-to-end at massive throughput. Architecture: (1) Publisher ad request—publisher sends bid request (RTB protocol, OpenRTB standard) with user ID, page context, ad slot specifications; (2) User data enrichment—parallel lookup of user features from a Redis cluster (sub-5ms); (3) Candidate retrieval—filter eligible ads by targeting criteria (demographic, geographic, keyword, topic) using an inverted index of ad targeting parameters; retrieve ~100–1000 candidates; (4) CTR scoring—batch inference on all candidates using a GPU-accelerated CTR model; (5) Auction execution—rank candidates by eCPM = bid × predicted_CTR; compute GSP prices; (6) Bid response—return winning ad creative and price within 50ms of receiving the bid request; (7) Impression logging—asynchronously log impression event to Kafka for billing, reporting, and training. Scaling: horizontal scaling of all stateless components; consistent hashing for user data routing; rate limiting per publisher to prevent overload. Monitor: bid response rate (percentage of requests with a winning bid), auction timeout rate, and median latency.
How should sample weighting be applied in CTR model training to correct for data imbalance and selection bias?
CTR training data has two forms of imbalance: class imbalance (far more non-clicks than clicks) and selection bias (we only observe impressions that the current system chose to serve). Corrections: (1) Positive sample weighting—assign higher weight to click events vs impression events; typical ratio: 1/(positive_fraction) for positive examples; this is equivalent to undersampling negatives; (2) Propensity weighting—weight each impression by 1/P(shown|context) to debias toward a uniform-exposure counterfactual; propensities estimated from a separate logging model; (3) Temporal weighting—give more weight to recent impressions via exp(-lambda × age_days) to adapt to distribution shift; (4) Domain weighting—if training across multiple ad formats, weight by inverse domain frequency to prevent the dominant format from overwhelming the minority; (5) Hard negative mining—periodically mine difficult-to-classify non-click examples (non-clicks from high-scoring ads) to sharpen the decision boundary. Apply all weights multiplicatively in the loss function. Monitor: weighted vs unweighted precision and recall to verify that weighting corrects rather than distorts the training distribution.
How do you handle the auction feedback loop where CTR predictions influence future training data?
CTR predictions determine which ads win auctions and receive impressions. Training data consists of impressed ads and their click outcomes. This creates a feedback loop: ads that the model predicts as high-CTR win more impressions, accumulate more click data, and become even higher in the model's predictions regardless of their true quality relative to unseen alternatives. Mitigation: (1) Exploration traffic—reserve a small percentage of impressions for random ad selection to collect unbiased data on all ad candidates; (2) Counterfactual evaluation—use doubly robust estimators to estimate what the CTR of non-selected ads would have been; (3) Bid diversification—ensure the auction doesn't always award the same ad to a given user; introduce randomness in tie-breaking; (4) Propensity scoring—weight training examples by the inverse probability of the ad being served given its context; (5) Logging policy tracking—store the current model version that made each serving decision; use it to compute propensities during training. Accept that some feedback loop is inherent; the goal is to minimize its magnitude through exploration and debiasing rather than eliminating it entirely.
How do you incorporate multi-modal ad creative features (image, video, text) into CTR prediction?
Ad creatives combine visual and textual elements whose quality significantly impacts CTR. Multi-modal feature extraction: (1) Image features—pass ad images through a ResNet or EfficientNet encoder; extract aesthetic quality score (trained on human ratings), detected objects and scenes (CLIP), color palette, presence of human faces and emotions; (2) Video features—extract per-frame embeddings, aggregate with temporal pooling; include video length, aspect ratio, audio presence; (3) Text features—encode headline and description using BERT or sentence transformers; compute sentiment, readability (Flesch score), call-to-action presence (keyword matching + classifier); (4) Cross-modal alignment—compute CLIP-based alignment score between image and text to detect creative inconsistencies; (5) Integration—concatenate all creative embeddings with user, context, and ad category features; pass through the CTR model. Challenges: video encoding adds 50–200ms latency; pre-compute video embeddings offline and cache them per ad creative. Monitor: creative feature importance via SHAP; track CTR differences between high and low aesthetic score ads to validate feature value.
What is bidding strategy optimization and how does it relate to CTR prediction?
Bidding strategy optimization helps advertisers automatically set bids to maximize their campaign objectives (clicks, conversions, ROAS) within a budget constraint. Smart bidding uses the platform's CTR and CVR predictions as key inputs. Architecture: (1) Predicted CTR and CVR—the platform computes P(click) and P(conversion|click) per impression; the advertiser's expected value per impression is bid = max_CPA × P(CVR) or max_ROAS × predicted_value / predicted_CVR; (2) Real-time bid adjustment—the bidding model adjusts the base bid for each auction based on context (high-value user, premium placement → higher bid; low-intent signal → lower bid); (3) Portfolio optimization—across multiple campaigns, allocate budget to auctions with the highest marginal return per dollar; (4) Constraint handling—ensure total spend meets the daily budget and average CPA or ROAS targets; (5) Feedback loop—actual conversion outcomes feed back weekly to recalibrate CVR predictions. Evaluation: compare auto-bidding campaigns to manual bidding on cost per conversion and ROAS improvement. CTR prediction accuracy directly limits smart bidding quality; a 10% CTR error translates to a 10% bid error.
How does the attention mechanism improve CTR prediction models for sequential user behavior?
Traditional CTR models use pooled aggregates of user behavior (average embedding of past clicked items). Attention mechanisms selectively weight past behaviors based on their relevance to the current ad candidate, enabling the model to focus on the most pertinent historical interactions. DIN (Deep Interest Network, Alibaba 2018) introduced local activation units: for each user historical item and the target ad, compute an attention weight = MLP(target_item_embed ⊙ history_item_embed); weighted sum of history embeddings produces a candidate-specific user representation. DIEN (Deep Interest Evolution Network) adds a GRU-based sequence model to capture temporal evolution of user interests before the attention layer. DISN extends this further with graph-based interest modeling. In practice: DIN attention over the last 50–200 interactions; attention weights are computed at inference time per candidate ad, adding some compute cost; compensate with reduced embedding dimensions. Benefits: significant lift in CVR and ROAS for personalized ads in e-commerce. Monitor: attention weight distribution for sanity (should focus on recent, relevant items rather than distributing uniformly).
How do third-party cookie deprecation and privacy regulations affect ads CTR systems?
Third-party cookie deprecation (Chrome's phase-out in 2025, completed 2026) and privacy regulations (GDPR, CCPA, iOS ATT) fundamentally limit cross-site user tracking, which is the backbone of behavioral ad targeting. Impact on CTR systems: (1) Loss of cross-site behavioral data—ad networks can no longer track user behavior across publishers using third-party cookies; user features become less rich; (2) Audience size reduction—retargeting audiences shrink dramatically; lookalike modeling becomes less accurate; (3) CTR prediction degradation—models relying on third-party behavioral features lose significant predictive signal; (4) First-party data importance—advertisers' own customer data (CRM, purchase history) becomes more valuable; clean room collaborations (Google Privacy Sandbox, Meta Advanced Matching) allow privacy-safe matching. Adaptation strategies: (1) Contextual targeting renaissance—invest in contextual CTR models using page content signals that require no user tracking; (2) Privacy-enhancing technologies—federated learning, on-device CTR prediction (privacy sandbox FLoC successor Topics API); (3) First-party data enrichment—encourage publishers and advertisers to collect and share first-party data with user consent. Monitor: model performance degradation over time as cookie coverage declines.
How do you use counterfactual logging to train unbiased CTR models?
Standard CTR training data only contains outcomes for ads that were actually shown—this creates selection bias because the training policy determines what data is observed. Counterfactual logging creates training data that can be used for unbiased policy evaluation and training. Process: (1) Log selection propensity—at serving time, for every ad that enters the auction, log the probability that each ad would win under a randomized exploration policy; (2) Exploration traffic—a subset of impressions are served using a randomized policy (epsilon-greedy or Thompson sampling) with known selection probabilities; (3) IPS training—weight each training example by 1/p(shown), producing an unbiased estimate of the reward under any target policy; (4) SNIPS (Self-normalized IPS)—normalize by sum of propensities to reduce variance; (5) Doubly robust estimator—combine a direct model with IPS for lower variance when the model is approximately correct. Practical challenge: propensities from a near-deterministic production system are very small (close to 0), causing extreme weight variance; exploration traffic with bounded propensities is essential. Store propensity scores as a column in the logging schema for all impressed and non-impressed (exploration) ads.
How does ad position affect CTR and how should position be handled in CTR models?
Ad position has a dramatic effect on CTR independent of ad quality: the first position receives 2–5x more clicks than the third position. This position bias contaminates click labels if not corrected. Handling: (1) Position as a training feature—include rank position as an input feature during training; the model learns to correct for position in its predictions; at inference time, set position to 1 (best position) or to its expected value to get a position-independent quality score; (2) Examination hypothesis—model P(click) = P(examine|position) × P(relevant); estimate examination probabilities via randomization; correct labels before training; (3) Propensity-weighted training—weight each training example by 1/P(examined at logged position); (4) Position-aware auction—some platforms set ad position before CTR prediction; the prediction must be conditioned on the expected position. The key design decision: should CTR represent 'probability of click if shown at position k' (position-conditional) or 'inherent ad quality independent of position' (position-independent)? The latter is needed for fair auction comparison. Use position-independent CTR for ranking; position-conditional CTR for revenue forecasting.
How do you design a system for real-time audience segmentation for ad targeting?
Real-time audience segmentation assigns users to targeting segments (interest categories, behavioral cohorts, demographic groups) used by advertisers to target their campaigns. Architecture: (1) Event stream processing—user page views, searches, and app interactions streamed to Kafka; Flink consumers classify each event by content category using a text/URL classifier; (2) Interest profile update—increment interest counters per user per category in Redis (TTL-decaying with half-life of 7 days); (3) Segment membership—for each predefined audience segment (e.g., 'in-market for a car', 'fitness enthusiast'), evaluate user interest profile against segment definition; update segment membership in real time; (4) Index update—update the inverted index mapping each segment to its members as users join/leave segments; (5) Ad targeting lookup—at auction time, look up the user's segment memberships (sub-5ms from Redis); use as a filter to select eligible ads; (6) Privacy—apply k-anonymity (minimum segment size of 1000 users) before surfacing to advertisers; model segment membership at a cohort level rather than individual level (Google Topics API design). Monitor: segment size distribution, membership freshness, and segment targeting utilization rate by advertisers.
What is normalized cross-entropy (NCE) and why is it preferred over raw log-loss for CTR model evaluation?
Normalized Cross-Entropy (NCE) measures a CTR model's improvement over a simple baseline that always predicts the background (population-average) CTR. Formula: NCE = log-loss(model) / log-loss(background_CTR_baseline). A value less than 1 indicates the model is better than the baseline; lower is better. Why preferred over raw log-loss: (1) Context independence—log-loss is affected by the background CTR of the dataset; a dataset with 1% CTR will have lower log-loss than one with 5% CTR for an identically calibrated model; NCE normalizes this away; (2) Comparability—NCE scores are comparable across datasets with different base CTR rates, enabling meaningful model comparison across ad platforms, campaigns, and time periods; (3) Business relevance—NCE directly quantifies how much value the ML model adds beyond a naive baseline, making it interpretable to non-technical stakeholders. Complementary metrics: AUC (ranking quality), calibration ECE (probability accuracy), and online CTR lift (real-world impact). In the industry, a 0.001 reduction in NCE at Google-scale translates to millions of dollars in annual revenue improvement.
How do you monitor a CTR prediction model in production for degradation?
CTR model degradation occurs due to distribution shift (new ad formats, seasonal patterns, audience changes). Monitoring framework: (1) Score distribution monitoring—track the daily mean and percentile distribution of predicted CTR scores; sudden shifts indicate distribution change; alert on greater than 10% shift in mean score from the 14-day average; (2) Calibration monitoring—daily computation of ECE on a sample of impressions with realized click labels; alert if ECE exceeds 0.02; (3) Online metrics—track platform CTR, revenue per query, and conversion rate daily; segment by ad format, publisher, and device; alert on greater than 3% drop from weekly baseline; (4) Feature drift monitoring—PSI on key input features (user activity features, ad age, time-since-last-click); PSI above 0.2 triggers immediate investigation; (5) Segmented performance—compute AUC and log-loss separately for new ads, returning advertisers, mobile vs desktop, and different ad formats to catch segment-specific degradation; (6) Prediction latency—monitor p99 inference latency; alert if it exceeds 20ms; (7) Model version tracking—maintain an audit log of all model deployments with associated performance metrics for rollback decisions.
How do you integrate a CTR prediction model with real-time bidding (RTB) infrastructure?
Real-Time Bidding (RTB) allows advertisers to bid on individual ad impressions via an auction conducted in under 100ms. CTR model integration: (1) Bid request processing—DSP (Demand-Side Platform) receives an OpenRTB bid request from the SSP (Supply-Side Platform) with user ID, page context, and ad slot parameters; (2) User feature lookup—parallel fetch from a user data store (Redis) using the user ID; timeout 5ms; use cached defaults on timeout; (3) CTR model inference—run the CTR and CVR models on the (user, ad, context) features; GPU-accelerated batch inference if bidding on multiple ad slots simultaneously; (4) Bid price computation—bid = target_CPC × predicted_CTR + adjustments for predicted quality and audience value; (5) Bid response—return the bid price and winning creative within the 50ms timeout; no response = no bid; (6) Win notification—if the DSP wins the auction, the SSP sends a win notice with the clearing price; update model and billing; (7) Loss notification—log non-win events as implicit feedback for exploration analysis. Monitor: bid response rate (target >95%), timeout rate, win rate by segment, and average CPM vs clearing price.
How do you apply model distillation to reduce CTR model serving costs?
Large CTR models (Wide & Deep, DCN-v2 with hundreds of millions of parameters) have high inference cost at billion-query-per-day scale. Knowledge distillation trains a small student model to mimic a large teacher model's predictions, reducing serving cost while preserving most accuracy. Process: (1) Teacher training—train a large, accurate CTR model (teacher) on click data with cross-entropy loss; (2) Soft label generation—run the teacher on all training examples to generate predicted CTR probabilities (soft labels); (3) Student training—train a smaller architecture (fewer layers, smaller embeddings) using a combination of the original hard labels (clicks) and soft labels from the teacher: Loss = alpha × KL(teacher_output, student_output) + (1-alpha) × cross_entropy(student, clicks); (4) Temperature scaling—use temperature T > 1 when computing soft labels to soften the teacher's probability distribution and provide richer gradient signal; (5) Evaluation—compare student and teacher AUC and NCE; target less than 0.5% AUC degradation for a 5-10x model size reduction. Deploy: student model on CPU at 5x lower serving cost; teacher retained for high-value ad slots. Benefits: typically achieve 5-10x throughput improvement with under 1% AUC loss.
How do you design an A/B testing framework for ads CTR model changes?
A/B testing CTR model changes requires careful experimental design to attribute revenue changes correctly. Framework: (1) Traffic splitting—randomly split auctions or users into control (current model) and treatment (new model) groups; user-level split preferred to avoid contamination within a user's session; (2) Primary metrics—RPQ (revenue per query), CTR, CVR, advertiser ROI; secondary metrics: ad quality score, user experience (hide rate, negative feedback rate); (3) Statistical rigor—compute minimum detectable effect based on baseline variance; use sequential testing (mSPRT) to enable early stopping; apply Bonferroni correction for multiple metrics; (4) Duration—run for at least 7 days to capture weekly patterns; avoid starting during major events (holidays, product launches); (5) Guardrail metrics—monitor user experience guardrails (excessive frequency, low-quality ads) and system guardrails (latency, error rate); automatic rollback if guardrails are violated; (6) Ramp-up—start at 1% traffic, monitor for 24 hours, ramp to 10%, then 50%, then 100% with automated safety checks at each stage. Post-experiment: compute confidence intervals for all metrics; document results in an experiment registry for future reference.
How do you prevent distribution shift between training and serving in a CTR model?
Training-serving distribution shift is one of the most common causes of CTR model degradation. Sources: (1) Training data time lag—model trained on 30-day-old data; user interests and ad landscape have shifted; (2) Feature computation inconsistency—features computed differently in offline training vs online serving (training-serving skew); (3) Sample selection bias—training only on impressions from the current system; excludes ads that would have performed well but were never shown; (4) Temporal feature leakage—using future signals as training features, creating unrealistically high training accuracy. Prevention: (1) Feature store unification—use the same feature computation code for training (offline batch) and serving (online real-time); validate with logged serving features vs training-time-computed features for the same events; (2) Continuous training—refresh models daily on recent data to reduce temporal distribution shift; (3) Data validation—monitor PSI on input features between training and serving; alert on PSI above 0.1; (4) Exploration logging—collect unbiased impressions via exploration traffic to reduce selection bias in training data; (5) Freshness requirements—set and enforce SLA on feature freshness (user features no older than 1 hour). Run a weekly skew check by comparing online feature distributions to offline training distributions.
Related topics in System Design
Put it into practice with AI Learning
This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.
- Free
- No account
- Works offline