Foundations to Frontier
Tests
N. MLOps and AI Systems Engineering › N4 Monitoring and Maintenance

A/B Testing in Production

Offline metrics choose candidates; online experiments decide what ships. Testing a model on live traffic sounds simple (split the users, compare a metric), but the numbers needed are large, the metric can reward the wrong behaviour, users react to novelty, and analysing at the wrong unit invents significant results. The exercises build a search engine with graded relevance and a position-based click model, implement team-draft interleaving, and measure how many queries an A/B test and interleaving need to detect rankers of different quality. Practice problems cover novelty effects, clickbait and satisfied-click metrics, Thompson sampling against an equal split, how well offline NDCG predicts the online winner, and the false positives caused by analysing queries instead of users.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The taste test

To learn which of two recipes people prefer, a restaurant can give half its customers recipe A and half recipe B and compare how much they eat. Hungry and light eaters land in both groups by chance, so the comparison needs many customers. Serving each customer a small plate of both and asking which they finished first removes the difference between customers and needs far fewer. Online experiments on models face the same choice: split users between versions, or show each user a blend of both.

🎮 MLOps lab

Offline NDCG@10: A 0.8381, B 0.8623. Online gain: 0.0303 clicks per query. Queries needed for 80% power:

A/B test (both arms)
38,585
interleaving, t-test
7,665
interleaving, sign test
7,930

Interleaving shows both rankers to the same user on the same query, so differences between users cancel: about 5.0× fewer queries. In 300 A/A tests, treating a user's queries as independent gave 44% false positives; a user-level analysis gave 6%.

Why engineers care

In Exercise 2, telling apart two rankers that differed by 0.03 clicks per query took about 38,600 queries in an A/B test and 7,700 with interleaving, five times fewer.

📝 Quick check (Level 0)
0/3 answered
  1. 1. An A/B test compares two versions by…
  2. 2. Interleaving shows each user…
  3. 3. Online tests are needed because…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • A/B test: randomize units (users, sessions, queries) between control A and treatment B and compare a metric with a two-sample test.
  • Sample size: for a two-sided test at level α with power 1 − β, each arm needs n = 2(z₁₋α/₂ + z₁₋β)²σ²/δ², where δ is the effect and σ² the variance of the metric per unit.
  • Interleaving: merge the two rankings into one list; team-draft interleaving lets the rankers take turns picking their best remaining document, with a coin flip deciding who picks first in each round, and credits each click to the ranker that contributed the document.
  • Novelty and primacy effects: users react to change itself, inflating or depressing early results.
  • Guardrail and satisfaction metrics: clicks can be gamed; dwell time, satisfied clicks and long-term retention are better signals of value.
  • Randomization unit and analysis unit: if users are randomized, the analysis must treat each user, not each query, as independent.
  • Bandits: adaptive allocation (topic B5-2) sends more traffic to the better version while the test runs.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Team-draft interleaving credits a click to…
  2. 2. The required sample size grows with…
  3. 3. A novelty effect is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

A search engine and its users

Exercise 1.

  • 20 candidate documents per query with relevance grades 0 to 3 (55%, 25%, 13%, 7%).
  • A ranker sees relevance plus Gaussian noise and shows the top 10; ranker A has noise 1.0, rankers B less.
  • Users examine position k with probability 1/k^0.8 and click an examined document with probability u × (0.02, 0.15, 0.4, 0.8) by grade, where u is the user’s click propensity (log-normal, some users click much more).
  • Offline metric: NDCG@10 from the grades. Online metric: clicks per query.
  • Team-draft interleaving of two rankings, with clicks credited to the contributing ranker.

Practice.

  • Compute the sample size before the test, from the metric’s variance and the smallest effect worth detecting.
  • Prefer paired designs (interleaving, within-user comparisons, variance reduction such as CUPED) when the metric allows.
  • Run long enough to see novelty fade, and check that the effect is stable over time.
  • Choose metrics that measure value, with guardrails against clickbait and latency regressions.
  • Analyse at the unit you randomized, and run A/A tests to check the whole pipeline.
# team-draft interleaving of rankings a and b
shown, team, used = [], [], set()
while len(shown) < K:
    order = (A, B) if coin() else (B, A)
    for t in order:
        doc = first_unused(a if t == A else b, used)
        shown.append(doc); team.append(t); used.add(doc)
clicks = observe(shown)
score_b - score_a = sum(clicks[team == B]) - sum(clicks[team == A])
🐍 Exercise 1: rankers, clicks and interleaving
Simulate graded queries, noisy rankers and a position-based click model, compute NDCG@10, and implement team-draft interleaving.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Interleaving needs fewer queries because…
  2. 2. A short test of a new ranker can overestimate its gain because of…
  3. 3. Analysing queries as independent when users were randomized…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Sample size. With per-unit variance σ² in each arm and effect δ, the difference of means has variance 2σ²/n, and a two-sided level-α test has power 1 − β when δ/√(2σ²/n) = z₁₋α/₂ + z₁₋β. Solving gives n = 2(z₁₋α/₂ + z₁₋β)²σ²/δ² per arm; for α = 0.05 and 80% power the constant (1.96 + 0.84)² is about 7.85. Halving the effect quadruples the sample.

Why pairing helps. In an A/B test the variance of clicks per query includes everything that differs between users and queries: how often a user clicks, how many relevant documents a query has. Interleaving measures the difference within each query, so these terms cancel and only the variance of the credited difference remains. In Exercise 2 that variance was small enough to need about five times fewer queries.

Clustered data. If users are randomized and user i contributes m queries whose metrics have correlation ρ, the variance of the mean is larger than the naive estimate by the design effect 1 + (m − 1)ρ. Treating queries as independent then underestimates the standard error by its square root, and an A/A test rejects far more often than α. Aggregating per user (or the delta method for a ratio of sums) restores the right variance.

Adaptive allocation. A bandit that shifts traffic to the better arm loses fewer clicks while learning, but its samples depend on past outcomes, so the usual confidence intervals no longer hold; it suits choosing among many variants more than estimating an effect for a launch decision.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Halving the effect to detect multiplies the sample size by…
  2. 2. The design effect for m queries per user with correlation ρ is…
  3. 3. Bandit allocation complicates…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How many queries does it take to tell two rankers apart online, by an A/B test and by interleaving?

History.

  • Controlled experiments go back to R. A. Fisher’s randomized field trials (1920s and 1935).
  • Online controlled experiments grew at Amazon, Google, Microsoft and others in the 2000s; R. Kohavi and colleagues (2009) set out practical guidance, and Kohavi, D. Tang and Y. Xu (2020) wrote the standard book.
  • T. Joachims (2002) proposed comparing rankers through balanced interleaving of their results; F. Radlinski, M. Kurup and T. Joachims (2008) introduced team-draft interleaving and showed that it agrees with A/B tests using far less traffic; O. Chapelle, Joachims, Radlinski and Y. Yue (2012) measured its sensitivity at scale.
  • A. Deng and colleagues (2013) proposed CUPED, variance reduction with pre-experiment data.

Exercise 2.

  • 60,000 queries; ranker A has noise 1.0, rankers B have noise 0.95, 0.9, 0.8 or 0.6.
  • The gain is measured from expected clicks; the variance from simulated clicks.
  • Queries needed for 80% power at the 5% level: both arms of an A/B test, interleaving with a t-test on the credited difference, and interleaving with a sign test on per-query wins.

Seed 0:

B noise NDCG@10 A NDCG@10 B gain in clicks per query A/B test interleaving, t-test interleaving, sign test
0.95 0.8373 0.8498 0.0157 143,613 28,750 32,691
0.9 0.8381 0.8623 0.0303 38,585 7,665 7,930
0.8 0.8370 0.8875 0.0634 8,860 1,678 2,149
0.6 0.8371 0.9366 0.1226 2,425 433 469

Check: in 200 simulated experiments at the computed sizes for B noise 0.6, the A/B test with 2,425 queries detected the gain 78.5% of the time and interleaving with 432 queries 84.0% of the time, close to the planned 80%.

Seeds 1 and 2: A/B tests needed 147,268 and 137,626 queries at noise 0.95 and 2,444 and 2,433 at noise 0.6; interleaving with a t-test needed 27,238 and 26,909, and 404 and 431. Measured power at noise 0.6: A/B 81.5% and 83.0%, interleaving 78.5% and 83.5%.

Findings.

  • Interleaving needed 5.0 to 6.1 times fewer queries than the A/B test across all gaps and seeds.
  • Required traffic grew roughly with the inverse square of the gain: about 2,400 A/B queries for a 0.12 gain, 144,000 for a 0.016 gain.
  • The sign test was close to the t-test at large gaps but noisy at the smallest (between 26,500 and 62,600 queries at noise 0.95 across seeds), because few queries have any credited clicks that differ.
🐍 Exercise 2 (research): how many queries does it take to tell two rankers apart online, by an A/B test and by interleaving?
Measure how many queries an A/B test and team-draft interleaving need to detect rankers of four different quality gaps, and check the power by simulation.

Online experiments in practice

  • Experimentation platforms (Microsoft ExP, Google’s overlapping experiment infrastructure, Netflix, Booking.com, and open tools such as GrowthBook and Eppo) run thousands of concurrent tests with automatic sample-size checks, guardrails and A/A tests.
  • Interleaving is used by search and recommendation teams (Bing, Yandex, Netflix, Airbnb) to screen rankers quickly before a confirmatory A/B test of business metrics.
  • Variance reduction with pre-experiment covariates (CUPED) and stratification often halves the required traffic.
  • Sequential tests and always-valid p-values allow stopping early without inflating false positives; peeking at an ordinary test does inflate them.
  • Remote-sensing products use the same ideas when comparing processing versions on matched scenes: paired comparisons on the same images remove the variation between scenes.

References

  1. R. A. Fisher (1935). The Design of Experiments. Oliver and Boyd.
  2. T. Joachims (2002). “Optimizing search engines using clickthrough data.” KDD.
  3. F. Radlinski, M. Kurup and T. Joachims (2008). “How does clickthrough data reflect retrieval quality?” CIKM.
  4. R. Kohavi, R. Longbotham, D. Sommerfield and R. M. Henne (2009). “Controlled experiments on the web: survey and practical guide.” Data Mining and Knowledge Discovery.
  5. O. Chapelle, T. Joachims, F. Radlinski and Y. Yue (2012). “Large-scale validation and analysis of interleaved search evaluation.” ACM Transactions on Information Systems.
  6. A. Deng, Y. Xu, R. Kohavi and T. Walker (2013). “Improving the sensitivity of online controlled experiments by utilizing pre-experiment data.” WSDM.
  7. R. Kohavi, D. Tang and Y. Xu (2020). Trustworthy Online Controlled Experiments. Cambridge University Press.