How do you run an A/B test to evaluate a new ML model?
Written by the mlprep team · Updated
How would you run an A/B test to evaluate whether a new ML model is better than the current one? What makes ML A/B tests different from standard product experiments?
An A/B test measures whether the new model produces better business outcomes on real traffic, not just better offline metrics. This is the ground truth — offline evaluation tells you the model is good on historical data; an A/B test tells you it's good for users.
Why not just use offline metrics#
Offline metrics (AUC, RMSE, NDCG) are computed on a held-out split of historical data. They don't capture:
- How users respond to model outputs (a higher-CTR recommendation model might burn user trust long-term)
- Feedback loops (model affects behavior, behavior affects future training data)
- Edge cases and distribution shifts in live traffic not represented in the historical holdout
An A/B test is the authoritative evaluation.
The setup#
Randomly split users (or sessions, or requests) into control (old model) and treatment (new model) groups. The split must be consistent — the same user should always see the same variant, otherwise they get mixed experiences and your measurements are noisy.
Randomize at the user level, not the request level, to avoid within-user contamination. Use a hash of user ID + experiment ID to deterministically assign variants.
Choosing the primary metric#
The primary metric should be:
- Sensitive to the change (actually affected by model quality)
- Aligned with business goals (not just the ML metric you optimized)
- Measurable within the experiment window
For a recommendation model, the ML metric might be NDCG, but the business metric is click-through rate, time-on-site, or revenue per session. Optimize for the business metric. Track the ML metric as a guardrail — a model with better NDCG should generally improve CTR, but if it doesn't, that's worth understanding.
Statistical power and sample size#
Before running, calculate the required sample size:
n ≈ 2 · (z_α + z_β)² · σ² / δ²
Where δ is the minimum detectable effect (the smallest lift you'd care about), σ² is the variance of the metric, z_α = 1.96 for α=0.05 (false positive rate), z_β = 0.84 for 80% power. If you need to detect a 1% lift on a metric with high variance, you need a lot of traffic.
Underpowered tests are dangerous — you'll frequently conclude "no difference" when there is one, or ship a bad model because you didn't have enough data to detect the harm.
What makes ML A/B tests harder#
Interference effects: if users interact with each other (social networks, marketplaces), a user in control sees content influenced by treatment users. The assumption of independent units breaks down.
Novelty effect: users might click more on new recommendations just because they're new. Run the test long enough (weeks, not days) for novelty to wear off.
Metric delay: conversion, churn, and LTV metrics require long windows. You can't always wait — use early proxy metrics (session engagement) alongside the delayed true metric.
Multiple comparisons: if you test 10 metrics, you'll find a "significant" effect by chance. Pre-register your primary metric before looking at results.
Interview red flags#
- Assuming a better offline metric guarantees an online win.
- Randomizing by request instead of user, so the same user sees both models and the assignment is not stable.
- Ignoring interference in marketplaces or social products, where treated users affect control users.
- Calling the test after a few days, before novelty effects settle and before delayed outcomes are measured.
You mentioned interference effects when users interact — how do you handle experimentation in systems where the model's output for one user affects other users?
The standard A/B test assumes SUTVA: the treatment applied to user A doesn't affect user B's outcome. This breaks in many ML-heavy systems.
Where interference happens#
Marketplaces: treatment sellers see a new ranking model and get more orders. This takes orders away from control sellers — the control group's outcomes are suppressed, making the treatment look better than it is.
Social networks: treatment users see a new feed algorithm and engage more, producing more content that control users also see. The feed quality improves for everyone, diluting the measured effect.
Ride-sharing / food delivery: treatment riders see better ETAs and convert more, claiming drivers from control riders. The control group experiences worse supply.
Cluster-based randomization#
Instead of randomizing at the user level, randomize at a cluster level where interference is contained. For a marketplace, randomize by geography (all users in Seattle are in control, all in Portland are in treatment). Interference happens within cities, not between them.
Tradeoff: fewer independent units (cities, not users), so you need more time or broader rollout to get statistical power. Also, clusters may differ systematically (Seattle users are different from Portland users), requiring careful covariate balancing.
Switchback experiments#
Time-based randomization: alternate the variant by time period (control for odd hours, treatment for even hours). Works for two-sided marketplaces where the system state (driver supply, inventory) resets between periods.
Requires careful carryover analysis — a long surge during treatment hours might deplete driver supply for the next control period.
In practice#
Most teams accept some interference and add guardrail metrics to catch the worst cases. Full isolation is expensive and often not worth it for small effects. For large infrastructure changes (new pricing, major ranking overhaul), invest in cluster randomization or use held-out geographic markets.
Go deeper: A/B test design and analysis covers step-by-step design and analysis, plus peeking corrections and sequential testing.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
A/B tests measure business outcomes on live traffic — the authoritative evaluation that offline metrics can't replicate. Randomize at the user level with consistent hashing, pre-register your primary metric, and size the experiment for sufficient statistical power before running. ML A/B tests face interference effects (when users affect each other), novelty bias, and metric delays — cluster-based randomization contains interference but requires more traffic to achieve power.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you handle a situation where your A/B test shows the new model wins on CTR but loses on a long-term engagement metric?
- What is a holdout group and why might you maintain one permanently in a recommendation system?
- How do you detect and correct for experiment contamination — users who were exposed to both variants?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions