How do you run A/B tests for ML models in production?
Written by the mlprep team · Updated
Walk me through how you'd design and interpret an A/B test for a new ranking model. What are the common failure modes?
Experiment design basics#
An A/B test splits traffic between control (old model) and treatment (new model). Randomization unit matters: randomize by user, not by request, to avoid the same user seeing both experiences and contaminating the result.
Define before launch:
- Primary metric: the one number that decides the launch (e.g., session engagement rate, revenue per user)
- Guardrail metrics: metrics that must not degrade — latency, error rate, complaint rate, coverage
- Secondary metrics: directional signals that help interpret the primary
Sample size and minimum detectable effect#
Sample size is determined by:
n ≈ 2 * (z_α + z_β)² * σ² / δ²
where δ is the minimum detectable effect (MDE), σ² is metric variance, z_α controls false positive rate, z_β controls power.
Practical implication: if your primary metric has high variance (session length, revenue), you need more traffic and longer runtime to detect small effects. For ranking improvements, 1-2% lifts are common, and detecting them may require one to four weeks at significant traffic.
Runtime#
Run at minimum one full week to cover weekly seasonality. Run two weeks if behavior shows strong weekend/weekday patterns. Do not stop early even if results look significant — peeking inflates false positive rate.
Common failure modes#
Flat result does not mean bad model. Before concluding the model failed, verify:
- Treatment is actually different: check score distributions, candidate overlap, ranking delta
- The experiment had enough power: compute post-hoc MDE given your actual sample
- Traffic was unaffected by confounders: launches, holidays, app version changes during the experiment
Novelty effect: users engage differently with new ranking for a few days because it's different, not better. Check metrics in the first few days vs final week separately.
Dilution: if only 10% of sessions actually trigger the new model (e.g., only certain surfaces), a 50/50 traffic split is 95/5 in affected sessions. Report lift on affected sessions, not all traffic.
Metric-objective mismatch: the model was trained to maximize CTR. The A/B test measures revenue. If the model improves cheap clicks but not conversions, it can look neutral or negative in revenue even though offline metrics improved.
Interpreting results#
Report effect size with confidence interval, not just p-value. A statistically significant but tiny effect (0.001%) may not be worth shipping. A large but noisy effect may be worth shipping anyway.
For guardrail metrics, use one-sided tests at looser thresholds — you care about preventing degradation, not proving improvement.
Senior/staff considerations#
At senior/staff level, experimentation is a system, not a one-off analysis. This means:
- A pre-experiment checklist: power calculation, metric logging audit, randomization check, holdback plan
- Automated experiment health monitoring: ratio metric stability, SRM (sample ratio mismatch), variant exposure balance
- A post-experiment process: document effect size, CI, guardrail status, segment analysis, and decision rationale — not just p-value and ship/no-ship
Sample ratio mismatch (SRM) is a critical check. If control gets 49.2% and treatment gets 50.8% of traffic when you expected 50/50, there is a logging, routing, or bucketing bug. A result from an SRM experiment is unreliable regardless of significance.
Common traps#
- Peeking at results and stopping early when significant.
- Declaring success on a metric that was not pre-specified.
- Ignoring segment performance: global lift can hide regressions in high-value cohorts.
- Treating flat results as proof the model is bad instead of checking experiment validity first.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
A/B tests for ML require: user-level randomization, pre-specified primary metric and guardrails, sufficient power, and fixed runtime covering weekly seasonality. Flat results are ambiguous — check that treatment actually differed, the experiment had power, and no confounders were present. Always check for sample ratio mismatch before interpreting results.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- What is sample ratio mismatch and why does it invalidate an experiment?
- Your experiment ran for two weeks and shows p=0.08 on the primary metric. Do you ship?
- How do you handle experiments where the label takes 30 days to observe but you need a decision in two weeks?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
How do you evaluate a new ranker using logs from an old policy?
How do you put confidence intervals on ML metrics?
How do you determine the sample size needed for an A/B test?
What is model calibration and how do you fix a miscalibrated model?