Ranking Sponsored Posts in a Feed: Objective, Features, Evaluation
Machine LearningModel answerLast updated
Design a sponsored-post ranking system for a social feed: define the objective, choose features, evaluate offline, and monitor in production under a tight latency limit.
Scenario
You work on the data and modeling team of a social network. Your team owns the system that chooses which sponsored posts appear in each user's feed. The business wants to grow ad revenue without making the product worse for the people using it.
What to cover
- Objective. Specify what the ranker optimizes. Explain how you trade off advertiser revenue against user-experience signals such as clicks, engagement, hides, and reports.
- Features. Propose user-side, ad-side, and context features that predict ad performance. Say how you handle brand-new ads and brand-new users.
- Offline evaluation. Describe how you would validate a candidate model using historical data before it reaches users, and how you would connect those results to an online experiment.
- Production monitoring. Describe how you would detect performance degradation, data problems, and unfair or biased delivery once the model is live.
Constraints
- Ranked results must be returned in under 100 ms.
- You have historical logs of impressions, clicks, and conversion events.
- Focus on reasoning and trade-offs, not on implementation code.
Hints
Hint 1
Rank by a single value expressed in money: expected advertiser value (bid times predicted action probabilities) plus a priced term for user experience, such as a penalty for hides. Ask what makes the probabilities safe to multiply.
Hint 2
The 100 ms limit rules out running a heavy model over every ad. Think in stages: cheap retrieval and filtering first, then progressively more expensive rankers on fewer candidates.
Hint 3
For evaluation, split by time rather than randomly, look at calibration as well as ranking quality, slice results by segment, and treat an online A/B test with guardrail metrics as the final judge.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing and assumptions
State scale up front so the design is grounded. For example: billions of daily users, several feed sessions each, and roughly one ad per handful of organic posts. That implies hundreds of thousands of ranking requests per second at peak, tens of millions of active ads, and only a few thousand eligible after targeting and budget filters. Advertisers bid on an objective (click, install, purchase) and are charged through an auction. The latency target is p99 under 100 ms.
Serving funnel (driven by the latency budget)
| Stage | Candidates | Model | Rough budget |
|---|---|---|---|
| Retrieval and targeting | millions to ~2,000 | Two-tower embeddings with ANN lookup | ~20 ms |
| Light ranker | ~2,000 to ~200 | Gradient-boosted trees or small MLP | ~15 ms |
| Heavy ranker | ~200 | Multi-task deep network | ~40 ms |
| Auction and policy | to final slots | Pricing, pacing, frequency caps, diversity | ~10 ms |
The remaining ~15 ms covers feature-store reads and network overhead. On timeout, fall back to light-ranker scores.
1. Objective
Rank by total value:
TotalValue = bid × P(click) × P(conversion | click) + λ₁·P(engage) − λ₂·P(hide or report)
- The first term is expected advertiser value (eCPM-style). Match it to the bid type: bid × pCTR for click bids, bid × pCTR × pCVR for conversion bids.
- The second part converts user experience into the same currency. Choose λ values through experiments at several settings and plot short-term revenue against long-term retention. A hide today often means fewer sessions, and therefore fewer ad impressions, later.
- Add an ad-load rule: show an ad only if its value beats the organic content it displaces.
- Calibration is essential. Probabilities are multiplied by bids and fed into an auction, so a model with strong AUC but biased probabilities will systematically over- or under-charge advertisers.
Model design. Use one multi-task network with shared lower layers and separate heads for click, conversion, and negative feedback. Conversion is only observed after a click, which creates sample-selection bias. Train over the full impression space (ESMM-style) to correct it. Conversions also arrive late, so use an attribution window or a delayed-feedback correction to avoid labeling slow converters as negatives.
2. Features
User: age bucket, country, language, device, OS, connection; long-term interest signals and learned embeddings; ad history (past CTR, hide rate, conversions per category, ad fatigue today); recent interaction sequence and session depth.
Ad: advertiser, campaign objective, bid; creative embeddings, format, call to action; landing-page quality; historical CTR/CVR at ad, campaign, and advertiser levels, smoothed with a Beta prior such as (clicks + α) / (impressions + α + β); ad age and remaining budget.
Context and crosses: feed position, surface, time of day, day of week; user × category affinity, user × advertiser history, user-creative embedding similarity.
Cold start:
- New ads back off to advertiser and category priors plus content embeddings, with a small exploration budget (for example Thompson sampling) to collect labels quickly.
- New users rely on context, demographics, and population priors, shifting toward real-time session behavior as it accumulates.
3. Offline evaluation
- Time-based split. Train on earlier days and test on the following day. Random splits leak future information and inflate results.
- Metrics. Use log loss or normalized entropy as the primary metric because it rewards calibrated probabilities. Report AUC for ranking quality. Check calibration (predicted over observed rate, near 1.0), overall and by bucket.
- Slice analysis. Break results down by country, device, new versus established users, new ads, small advertisers, and demographic groups. A global gain can hide a regression in an important slice.
- Counterfactual estimates. Use replay or inverse propensity weighting on randomized exploration traffic to estimate revenue effects before launch.
- Online A/B test. Randomize by user. Primary metrics: revenue per user and advertiser outcomes (conversions, return on ad spend). Guardrails: hide rate, session time, daily actives, latency. Keep a long-term holdout to catch slow engagement erosion. Because advertiser budgets are shared across arms, interference is a risk, so consider budget-split or cluster-based designs.
4. Production monitoring
- Model health: hourly log loss and calibration from fresh labels; the distribution of predicted CTR (a sudden shift often signals a broken feature).
- Data health: feature drift (PSI), null rates, feature-store freshness, label-pipeline delays.
- Business health: revenue, eCPM, CTR, hide rate, advertiser cost per action versus target, with alerts against seasonal baselines.
- System health: p99 latency, timeout and fallback rates.
- Bias and fairness: compare delivery across demographic groups against the eligible audience, especially for regulated categories such as housing, employment, and credit. Track exposure share for small and new advertisers too.
- Feedback loops: the model trains on exposures it chose. Keep a slice of exploration traffic to preserve unbiased training data.
Common mistakes
- Optimizing clicks alone.
- Ignoring calibration.
- Random train/test splits.
- Reporting only global AUC.
- Ignoring auction and budget effects in experiments.
- Never addressing latency or the multi-stage funnel.
Likely follow-ups
- Sudden behavior shifts (holidays, major events): retrain frequently or update online, add time-aware features, and widen alert thresholds around known events.
- Why not maximize revenue only? Short-term revenue gains from aggressive ad load erode retention, which lowers long-term revenue.
- Model got better offline but worse online: suspect miscalibration, training/serving skew, feedback loops, or auction interference.