Design an Online Experiment for a Two-Stage ML Ranker
Machine LearningModel answerLast updated
Design an A/B test to evaluate a new learned second-stage ranker, covering metric choice, experiment validity, novelty effects, and post-experiment rollout decisions.
Context
You work on the search team at a large e-commerce platform. The current system uses a two-stage pipeline:
- Stage 1 (retrieval): A fast approximate model that returns the top-500 candidates from millions of items.
- Stage 2 (ranker): A gradient-boosted tree model that reorders the top-500 and serves the top-20 to the user.
Your team has trained a new deep learning second-stage ranker. Offline evaluation shows a +4% NDCG@20 improvement on a held-out set. You are now asked to design and run an online experiment to decide whether to ship it.
What is expected
Walk through your full experiment design as you would in an interview. Cover:
- Metric selection — primary, secondary, and guardrail metrics; why NDCG alone is not enough.
- Experiment setup — unit of randomization, traffic split, duration, and any stratification.
- Validity threats — novelty effects, interference, position bias, and how you handle each.
- Statistical considerations — power analysis sketch, multiple testing, and when to stop early.
- Interpretation and launch decision — how you reconcile offline vs. online metrics, what a "mixed result" looks like, and the rollout strategy.
Hints
Hint 1
NDCG is a ranking quality metric, but the business cares about something else — what is the bridge metric, and why might they diverge?
Hint 2
Two users on the same household device, or the same user across sessions, can break the independence assumption — how does your randomization unit address this?
Hint 3
The new deep model is more expensive to serve. How does latency factor into your guardrail metrics and your rollout plan?
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Metric Selection
Primary metric: Revenue per session (or GMV per session) NDCG measures ranking quality against human-labeled relevance, but relevance labels do not always equal purchase intent. A model that ranks popular but lower-margin items highly could lift NDCG while hurting revenue. Revenue per session is the metric the business actually optimizes.
Secondary metrics:
- Click-through rate (CTR) on rank positions 1–5 (sensitive, moves fast)
- Add-to-cart rate and conversion rate (confirms the click signal is real purchase intent)
- Return/refund rate (guards against the model surfacing misleading listings)
- Position bias proxy: CTR at rank 1 vs. ranks 6–10 ratio (checks whether the model is just inflating top-slot traffic)
Guardrail metrics (must not regress):
- p99 serving latency — the deep ranker is more expensive; a >20 ms increase at p99 is a hard stop.
- Error rate and fallback rate — if the new model fails, the system falls back to the old ranker; a spike here indicates instability.
- Diversity / catalog coverage — a model that over-indexes on a narrow set of items could hurt long-tail sellers and create business risk.
Why offline NDCG can diverge from online revenue:
- Labels are collected under the old ranker (position bias in label collection).
- Held-out set may not reflect live distribution shift (seasonality, new items).
- NDCG ignores complementary purchases and session-level dynamics.
- A +4% NDCG lift is promising but roughly translates to ~0.5–1.5% revenue lift in practice — the confidence interval around that is wide.
2. Experiment Setup
Unit of randomization: User (not session, not request) Randomizing at the session level risks the same user seeing both rankers, creating carry-over effects (they may change behavior based on earlier sessions). Randomizing at the user level preserves independence.
Edge case: Shared devices (family accounts) create contamination. If user IDs are device-based, switch to a logged-in user identifier or cookie-stability check.
Traffic split: Start with a 10% treatment / 10% holdout (not 50/50) because:
- The deep ranker is unproven at scale; a smaller initial exposure limits downside.
- You still get adequate power for large effects.
- Ramp to 50/50 only after confirming no latency or error rate regressions in the first 48 hours.
Duration:
- Minimum: 2 full weeks to capture weekly seasonality (weekday vs. weekend shopping patterns differ substantially).
- Power calculation sketch: assume baseline conversion rate ~3%, MDE of +0.15% (5% relative lift), two-tailed α = 0.05, power = 0.80. Using the standard formula n ≈ 2(z_α/2 + z_β)² · p(1−p) / δ², with p=0.03 and δ=0.0015, you need roughly 300,000–400,000 users per arm. At 10% traffic split on a large platform this is typically achievable within 2 weeks.
Stratification: Stratify randomization by platform (mobile web, iOS, Android, desktop) because ranker behavior and layout differ. Report results per stratum; a lift on mobile that vanishes on desktop is a real signal, not noise.
3. Validity Threats
Novelty effect: Users may click more on new result orderings simply because they are different, not because they are better. Mitigation: extend the experiment to at least 2 weeks and plot the treatment effect over time. If CTR lifts in week 1 but decays in week 2, it is a novelty artifact. Revenue, which requires completing a purchase, is less susceptible than CTR.
Interference / network effects: On an e-commerce platform, inventory and pricing are shared. If the treatment group buys out a popular item, the control group may be unable to purchase it (cannibalization). This is a weak threat for a ranker experiment (unlike a pricing experiment) but worth monitoring via inventory depletion rates in top-ranked items.
Position bias in evaluation: The new ranker changes positions. Items at rank 1 always get more clicks regardless of quality. Use inverse-propensity-score-weighted CTR (IPS-CTR) or at minimum compare CTR at fixed rank slots between arms rather than overall CTR.
Query distribution shift: The two rankers may respond differently to tail queries. Report primary metrics segmented by query frequency (head / torso / tail). A win on head queries masking a loss on tail queries is a launch risk.
4. Statistical Considerations
Multiple testing: With ~6–8 metrics tracked, apply Benjamini-Hochberg correction on secondary metrics. The primary metric (revenue per session) uses a pre-registered α = 0.05 without correction; guardrails use a one-sided test at α = 0.10 (we care about regression, not improvement).
Early stopping: Avoid peeking without a sequential testing framework. Use an always-valid p-value method (e.g., mSPRT / e-values) or a pre-specified interim analysis at day 7 with a Bonferroni-adjusted threshold (α = 0.025 at interim, 0.025 at final). Do not stop early for a positive result on conversion alone; wait for revenue confirmation.
Variance reduction: Use CUPED (controlled-experiment using pre-experiment data) — regress the outcome metric on the user's pre-experiment behavior to reduce variance, shrinking the required sample size by 20–40%.
5. Interpretation and Launch Decision
Reconciling offline vs. online: A +4% offline NDCG lift translating to a ~+1% online revenue lift is consistent and expected. If the online lift is near zero despite positive NDCG, investigate label bias: the training labels were likely collected under the old ranker's position distribution, causing the model to learn position rather than true relevance.
Mixed result example: Suppose revenue per session is +0.9% (p=0.03, significant) but p99 latency increased by 35 ms. This is a mixed result. The correct decision is: do not ship as-is. Options:
- Model distillation or quantization to recover latency.
- Feature reduction (drop the 5 most expensive features, retrain, re-experiment).
- Async pre-computation of scores for top-N candidates to shift latency off the critical path.
Rollout strategy:
- Ship to 10% → monitor for 48 hours → ramp to 50% → full rollout over 1 week.
- Keep a 5% holdback group for 4 weeks post-launch to measure long-term effects (e.g., session frequency change).
- Set up automated rollback triggers: if p99 latency exceeds threshold or error rate doubles, auto-revert within 5 minutes.
Common Mistakes
- Treating NDCG improvement as sufficient to launch — online metrics are the ground truth.
- Randomizing at the session or request level and then analyzing at the user level (unit of analysis mismatch inflates false positive rate).
- Stopping the experiment early based on a p-value crossing 0.05 on day 4 (peeking without sequential correction).
- Ignoring latency as a guardrail — a slower ranker degrades experience on low-end devices, which often represent the highest-growth user segment.
- Forgetting to segment by query type, platform, and user tenure — aggregated results can hide important heterogeneity.