Design and Analyze a Counterfactual Online Experiment for a Ranking Model
Machine LearningModel answerLast updated
Design an online experiment to measure the causal impact of a new ML ranking model, handling interference, novelty effects, and metric trade-offs at scale.
Scenario
You are a senior ML engineer at a large e-commerce marketplace. Your team has trained a new item-ranking model that, in offline evaluation, improves NDCG@10 by 4% and predicted purchase rate by 2.1% over the current production model.
Your manager asks you to run an online experiment before shipping. The platform serves 50 million daily active users and processes roughly 200 million search sessions per day. Items on the platform can appear in multiple users' feeds simultaneously, and seller inventory is shared across all users.
What is expected
Answer the following, reasoning step by step:
-
Experiment design — What type of online experiment would you run? Justify your randomization unit choice and explain any interference risks specific to a marketplace ranking problem.
-
Metric selection — Which primary and guardrail metrics would you choose, and why? Discuss the tension between short-term engagement metrics and long-term business metrics.
-
Novelty and primacy effects — How would you detect and handle them in this experiment?
-
Statistical considerations — How long should you run the experiment? What sample size or power calculation approach would you use? How do you handle multiple comparisons?
-
Decision framework — The experiment shows a statistically significant +1.8% lift in purchases but a −0.6% drop in session length. How do you decide whether to ship?
-
Failure modes — Name at least three subtle ways this experiment could give you a misleading result even if implemented correctly.
Hints
Hint 1
Consider how shared seller inventory creates interference between treatment and control groups — this is called a market-level spillover effect. How would you detect or bound it?
Hint 2
For novelty effects, think about whether the change in user behavior is driven by genuine model improvement or just user curiosity about seeing different results. What cohort analysis would reveal this?
Hint 3
When two metrics move in opposite directions (purchases up, session length down), think about whether that is actually a bad sign — what causal story could make both movements a positive outcome?
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Experiment Design and Randomization Unit
Unit of randomization: user (cookie/account ID), not session or query.
Randomizing at the session or query level creates within-user contamination: the same user sees both models and can compare results, inflating variance and potentially learning effects. User-level randomization gives a cleaner intent-to-treat estimate.
Allocation: Start with a 90/10 or 95/5 split (control/treatment), not 50/50. The new model's offline gains are promising but untested online. A small treatment ramp limits revenue risk if the model degrades on tail queries.
Interference — the hard part for marketplaces:
Marketplace ranking has a classic supply-side interference problem. If the treatment model pushes high-demand items to the top of results for 5% of users, it may deplete inventory or inflate prices for the 95% control users. This violates the Stable Unit Treatment Value Assumption (SUTVA).
Mitigation strategies:
- Switchback (time-based) experiments: alternate the entire platform between model A and model B in time windows (e.g., 30-minute blocks). Eliminates cross-user spillover but introduces time-of-day confounding. Useful as a complementary check.
- Geo-based holdout: assign all users in certain geographic markets to treatment. Limits inventory spillover to within-market effects.
- Bounding analysis: run the user-level A/B test and separately estimate the magnitude of spillover by measuring control-group purchase rates as a function of treatment-group traffic share in the same item category. If spillover is small relative to the observed effect, proceed.
2. Metric Selection
Primary metric: Purchase conversion rate (purchases / search sessions). Directly tied to revenue and the model's stated objective.
Secondary metrics:
- Gross merchandise value (GMV) per session — captures order size, not just conversion count.
- Return rate / refund rate (with a 30-day lag) — a model that ranks visually appealing but inaccurate items may inflate short-term conversions at the cost of returns.
Guardrail metrics (must not regress significantly):
- Seller diversity index — a new ranking model could over-concentrate purchases on a few sellers, creating marketplace health risk.
- p99 query latency — ranking model inference must not degrade tail latency beyond SLA (e.g., +5 ms).
- Session abandonment rate — users leaving without clicking anything.
Tension: Engagement metrics like click-through rate or session length are tempting because they are high-volume and low-noise. But they are proxies. A model that shows more relevant items may generate fewer clicks per session (user finds what they want faster) while increasing purchases. Optimizing for engagement metrics can lead to a locally optimal but globally harmful ranking.
3. Novelty and Primacy Effects
Novelty effect: Users exposed to a new ranking may click more initially due to curiosity, inflating early engagement. This decays over time toward a true steady state.
Primacy effect (also called "position primacy bias"): Users may be anchored to the old ranking and initially engage less with unfamiliar orderings, deflating early metrics.
Detection approach:
- Plot the treatment effect (lift in conversion rate) day-by-day over the experiment window.
- If the lift is large early and shrinks toward zero, suspect novelty. If it starts negative and grows toward positive, suspect primacy/learning.
- Segment users by cohort: users who entered the experiment on Day 1 vs. Day 7 vs. Day 14. If the Day-1 cohort shows a different effect size than later cohorts at the same exposure duration, a novelty/primacy effect is likely present.
Mitigation:
- Run the experiment for at least 2–4 weeks, long enough for novelty to decay (typically 1–2 weeks).
- Use the stabilized effect estimate (last week of a 4-week experiment) as your primary decision metric, not the cumulative average.
4. Statistical Considerations
Sample size / power:
For a 2% baseline purchase rate, detecting a +0.2 percentage point absolute lift (10% relative) at 80% power and α = 0.05 (two-sided) requires roughly:
n ≈ 2 × (z_α/2 + z_β)² × p(1−p) / δ²
n ≈ 2 × (1.96 + 0.84)² × 0.02 × 0.98 / (0.002)²
n ≈ 2 × 7.84 × 0.0196 / 0.000004
n ≈ ~76,800 users per arm
At 200M sessions/day with a 5% treatment ramp (~10M users/day), you reach this in hours. The binding constraint is therefore not sample size but experiment duration: you need enough days to capture weekly seasonality (run at minimum 1 full week, ideally 2–4).
Multiple comparisons: With ~6 metrics tracked, apply Benjamini-Hochberg FDR correction rather than Bonferroni (less conservative). Pre-register your primary metric before the experiment starts to prevent p-hacking.
Variance reduction: Use CUPED (Controlled-experiment Using Pre-Experiment Data) — regress out each user's pre-experiment purchase rate from the outcome. Typical variance reduction is 20–40%, effectively cutting required experiment duration.
5. Decision Framework: +1.8% Purchases, −0.6% Session Length
First, ask whether the session length drop is a bug or a feature.
A plausible causal story: the new ranking model surfaces more relevant items earlier in the result list. Users find what they want faster, purchase sooner, and leave. Session length drops because relevance improved. This is a positive outcome.
Decision checklist:
- Is the −0.6% session drop statistically significant? If not (wide CIs), do not treat it as a regression.
- Is GMV per session flat or positive? If purchase rate is up and GMV is flat, average order value dropped — investigate.
- Are guardrail metrics clean? Latency, abandonment, seller diversity all within bounds?
- Is the return/refund rate stable? (May require waiting 30 days.)
- Does the session-length drop persist across user segments (new vs. returning users, mobile vs. desktop)? A drop only in new users could indicate confusion.
Recommended decision: Ship if GMV per session is flat or positive, guardrails are clean, and the causal story (faster task completion) is internally consistent. Document the session-length interpretation explicitly for future reference.
6. Subtle Failure Modes
-
Simpson's paradox across device types: Mobile users (60% of traffic) have lower baseline conversion. If treatment is accidentally over-represented on desktop, aggregate lift appears larger than it truly is. Always check covariate balance at randomization.
-
Survivorship bias in long-run metric analysis: Users who remain active 4 weeks into the experiment are self-selected high-engagers. If you analyze only "long-run" users, you overestimate the treatment effect on the general population.
-
Leakage through recommendation emails or push notifications: If the platform sends personalized emails using the production (control) model for all users, treatment-group users receive emails inconsistent with their on-site experience, diluting the measured lift.
-
Peeking and early stopping: Checking significance daily and stopping when p < 0.05 inflates Type I error to ~30% over a 4-week window. Use sequential testing methods (e.g., mSPRT) if early stopping capability is required.
-
Inventory depletion as a confounder: A viral event (e.g., a holiday sale) during the experiment window depletes inventory faster in treatment (because it ranks popular items higher), making the treatment appear worse in the second half of the experiment due to stockouts rather than model quality.