Designing a Sponsored Product Ranking System for Search
Machine LearningModel answerLast updated
Design an end-to-end ML pipeline that selects and ranks paid listings in e-commerce search results, balancing advertiser value, user relevance, and platform revenue.
Background
You work on the monetization team at a large e-commerce marketplace. Every time a shopper runs a search, the platform needs to decide which sponsored listings to show, how to order them, and how much to charge the advertisers. Done well, this drives revenue while keeping the shopping experience useful. Done poorly, it annoys users and trains advertisers to waste their budgets.
Your Task
Walk through a high-level design for this sponsored listing ranking system. Cover each of the following areas in your answer:
-
Utility and Objective Formulation How do you define what makes a single ad slot "good"? The platform cares about revenue, the shopper cares about relevance, and the advertiser cares about return on spend. Describe a scoring formula that balances these three, and explain the auction mechanism you would use to translate scores into prices.
-
ML Model Architecture What model structure would you use to predict click-through rate (CTR) and conversion rate (CVR) for a given (user, query, ad) triple? Describe the features, network design, and how you would handle the fact that conversions are only observable for ads that were clicked.
-
Retrieval and Multi-Stage Ranking With tens of millions of active ads and a strict latency budget, you cannot score every candidate with a heavy model. Describe the funnel you would use to go from the full ad inventory down to the handful of slots on the results page.
-
Position Bias Ads shown in the top slot receive more clicks simply because of their position, not because they are more relevant. Explain why this poisons your training data and describe at least one concrete technique to correct for it.
-
Experimentation and Launch Criteria How would you evaluate a new model version offline, and what would a safe online rollout look like? Call out any experiment design risks specific to an ads marketplace.
There is no single correct answer. Interviewers evaluate whether you can reason coherently across the full pipeline and whether you understand the parts that are unique to ads systems: calibrated probabilistic predictions, auction mechanics, and biased logged feedback.
Hints
Hint 1
Start by writing out the scoring formula explicitly: score = bid × predicted probability (plus any relevance term). This forces you to separate the prediction problem (what is pCTR/pCVR?) from the optimization problem (how does the auction use those predictions?), which is the central distinction in ads ranking.
Hint 2
Conversions are only logged for items a user clicked. If you train a CVR model only on clicks, it sees a biased subset of impressions and learns the wrong thing. Look up ESMM (Entire Space Multi-task Model) or think about how to reformulate the target so you can train on all impressions instead of just clicked ones.
Hint 3
Position bias creates a feedback loop: high-slot ads get more clicks, the model thinks they are better, so they keep winning the top slot. The PAL (Position-Aware Learning) approach handles this by adding a shallow 'examination' tower trained on position, then dropping it at serving time so scores reflect quality alone, not position.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Scoping and Assumptions
Before diving in, state your operating assumptions. A useful set:
- Scale: ~500M daily active users, ~2B searches per day (~25k average QPS, ~75k peak).
- Inventory: ~10M active sponsored listings; each search page shows 2–6 ad slots mixed with organic results.
- Latency budget: ~100ms end-to-end for the ads pipeline (retrieval + ranking + auction).
- Bid types: CPC (pay per click) and target-CPA (pay per purchase), each with a daily budget cap.
- North-star metrics: platform ad revenue, advertiser return on ad spend (ROAS), and user satisfaction (measured by organic engagement as a guardrail).
1. Objective and Auction Design
Rank each candidate ad by its expected value per impression to the platform:
score(a) = eCPM(a) + α · relevance(a) − β · harm(a)
eCPM(a) = bid_cpc × pCTR(a) # CPC campaigns
= bid_cpa × pCTR(a) × pCVR(a) # CPA campaigns
relevance(a) = pCTR(a) × pCVR(a) × item_quality # user utility proxy
harm(a) = P(user hides or reports ad a) # experience guardrail
αandβare tuned via long-running experiments, not offline metrics alone.- Run a Generalized Second Price (GSP) auction on
score: winners pay the minimum bid required to hold their slot. Becausescoreis quality-adjusted, a low-quality ad must bid higher per click to rank equivalently — this discourages low-relevance advertisers from dominating by budget alone. - Add a reserve price (a floor below which no ad is shown) and a per-page ad load cap so the system leaves a slot empty rather than fill it with a poor match.
Why calibration is non-negotiable: pCTR and pCVR are multiplied by real money. A pCTR that runs 20% too high overcharges advertisers and misranks candidates. Apply isotonic regression or Platt scaling per segment, and monitor the predicted/observed ratio as an operational metric.
2. Multi-Task Ranking Model
Use a multi-task deep ranking model (DCN-v2 or MMoE backbone) with separate heads for pCTR, pCVR, and harm probability.
Feature groups:
- Sparse ID embeddings: user, item, advertiser, shop, category.
- Query representation: a fine-tuned text encoder embedding; token-level match features.
- User history: a target-attention sequence over recent views and purchases.
- Item content: title embedding, image embedding, price, recency.
- Context: device, time of day, slot number (training only — see Section 4).
- Cross features: query–item semantic similarity, historical CTR by (ad, query) pair.
Handling CVR selection bias (the core modeling challenge): conversions are only logged for clicked items. Training a CVR head only on click samples means the model never sees non-clicked impressions, so it learns a biased conditional distribution. The fix is the ESMM formulation: model pCTCVR = pCTR × pCVR as a single target trained over all impressions, while pCTR is trained on all impressions as usual. The CVR tower is then derived implicitly across the full impression space rather than the biased click subset.
Cold start for new ads: new listings have no ID-level click history. Mitigate this by (a) training with ID-embedding dropout so the model learns to rely on content features when IDs are absent, (b) initializing new ad embeddings from the centroid of similar items in the same category, and (c) running a bounded exploration boost for new ads during the first 48–72 hours.
Training cadence: retrain incrementally (hourly mini-batches or online learning) because ad inventory, bids, and budgets change throughout the day.
3. Retrieval and Ranking Funnel
With 10M ads and a 100ms budget, you need a multi-stage funnel:
- Query understanding — spell correction, category intent classification, synonym expansion.
- Retrieval (~10M → ~5k): keyword/targeting index match, plus two-tower approximate nearest-neighbor (ANN) retrieval via FAISS or ScaNN. Apply hard filters for budget exhaustion, geo targeting, policy violations, and out-of-stock items.
- Light ranker (~5k → ~300): a small GBDT or shallow two-tower model that produces a cheap eCPM estimate. Eliminates clear mismatches quickly.
- Heavy ranker (~300 → ~50): the full multi-task model from Section 2. Full feature computation happens here.
- Auction and re-ranking: compute final scores, apply reserve prices, run GSP, then blend ad slots with organic results. Enforce diversity constraints: at most one ad per shop, no ad duplicating an organic result on the same page.
- Budget pacing: a separate controller throttles each advertiser's participation rate so their daily budget spends smoothly rather than exhausting in the first hour.
4. Position Bias Correction
The problem: users click more on slot 1 regardless of ad quality. Naively trained on this data, the model learns "ads that ranked high historically are better." This creates a self-reinforcing loop that disadvantages new or challenger ads.
PAL (Position-Aware Learning): add a shallow "examination bias tower" that takes only position as input and outputs an examination probability. The full model becomes:
P(click) = P(examined | position) × P(click | examined, ad features)
During training, both towers are active. At serving time, the position tower is dropped (or set to a constant), so scores reflect ad quality alone, not the position they happened to occupy during data collection.
An alternative is inverse propensity weighting (IPW): estimate examination propensities from a small randomized position-swap experiment, then reweight each training example by 1 / propensity(position). IPW is simpler to implement but noisier; PAL tends to generalize better at scale.
5. Evaluation and Launch
Offline:
- Normalized cross-entropy (logloss) and GAUC per query to assess ranking quality.
- Calibration ratio (predicted / observed) broken down by position, category, and ad age.
- Counterfactual auction replay: simulate revenue and advertiser cost on held-out logged traffic using IPS-corrected estimates from exploration data.
Online A/B test:
- Primary: revenue per thousand searches, advertiser ROAS, CTR, CVR.
- Guardrails: organic search engagement (must not degrade), ad hide/report rate, p99 latency.
- Marketplace interference caveat: treatment and control users compete for the same advertiser budgets, so one group can steal budget from the other — contaminating results. Use budget-split randomization (assign advertisers, not users, to arms) or at minimum acknowledge this as a known bias in interpretation.
Post-launch monitoring:
- A 1–5% long-running holdout (weeks) to detect slow-burn effects like user ad fatigue or gradual advertiser churn.
- Real-time dashboards tracking calibration drift and feature distribution shift.
Common Mistakes to Avoid
- Ranking by bid alone — ignores relevance, degrades user experience, and is exploitable by high-bidding low-quality advertisers.
- Optimizing AUC without checking calibration — a well-ranked but poorly calibrated model misprices the auction.
- Training CVR only on clicks — produces a biased estimator; ESMM or a similar full-space formulation is the standard fix.
- Ignoring marketplace effects in experiments — budget sharing between arms can make a neutral change look positive or negative depending on which arm gets more competitive inventory.