AI State of the Art
MLOps/MLOps Pipeline/22 min
Section 194

A/B Testing and Canary Deployments for Models

Listen as a podcast →

The Big Gap: Lab vs Reality

Imagine a recommendation model. In offline evaluation, it hits 95% accuracy on your test set. You deploy it to production. And clicks plummet. Why? Because accuracy on a static dataset has nothing to do with real user behavior.

This gap between offline metrics (accuracy, F1, perplexity) and business results (click-through rate, revenue, satisfaction, retention) is the fundamental problem of ML in production. Offline metrics tell you if the model "understands" the data. Business metrics tell you if it creates value.

Deploying a model is like pulling a parachute: you don't really know if it works until you open it in real conditions. Progressive deployment strategies are your safety nets.

The real test is real users

Measuring "our model correctly predicts 95% of cases" is easy and comforting. Measuring "our model generates more revenue" or "users are more satisfied" is much harder, but it's the only question that matters in production. Offline metrics are indicators, business metrics are the verdict.

A/B Testing: The Scientific Showdown

A/B testing is the most rigorous method for evaluating the real impact of a new model. The principle is simple: split your users into two random groups.

  • Group A (control): receives the current model (the baseline)
  • Group B (test): receives the new model you want to evaluate

Measure a business metric you actually care about (click-through rate, revenue per session, time spent, NPS satisfaction). After collecting enough data, a statistical analysis tells you whether the observed difference is real or due to chance.

The Ingredients of a Good A/B Test

Before launching a test, clearly define:

The hypothesis: "Our new recommendation model will increase the click-through rate by 2% compared to the current model." A precise and measurable hypothesis.

The primary metric: usually not the model's accuracy, but something business-related. Conversion rate, engagement, revenue, ticket resolution time. This is the metric you'll base your decision on.

Guardrail metrics: the things that absolutely must not degrade. Latency must stay under X ms. The error rate must not increase. Day-7 retention must not drop. A model that increases clicks but drives users away long-term is a bad model.

The required sample size: how many users do you need to detect a 2% difference with 95% confidence? That depends on your metric's variability and the expected effect size. There are online calculators for this, and ignoring them is a classic mistake.

The duration: one week minimum, often two to four. Watch out for seasonal cycles: a test launched on Monday and stopped on Wednesday doesn't capture weekend behavior.

The peeking trap: don't look too early

It's tempting to check results after 2 hours and get excited: "B is at +5%!" But with little data, statistical fluctuations are huge. If you stop the test at that point because you like the results, you've introduced a major bias. Either define the duration upfront and wait, or use "sequential tests" that let you check progressively without biasing results.

Chart titled The effect of peeking at your AB test results before data collection is complete. The x axis is the number of samples collected from 0 to 450, the y axis the Type I error rate from 0 to 0.6. A dashed horizontal line marks the alpha equals 0.05 threshold. The blue No Peeking curve stays pinned to that threshold. The orange, red and dark red curves, corresponding to peeking every 50th, 20th and 10th sample, rise to roughly 0.23, 0.29 and 0.35. The black Every Sample curve, which checks after every new user, reaches nearly 0.47.
The cost of peeking, simulated on tests where A and B are in fact identical. Never looking before the end gives the expected 5% error rate (blue curve pinned to the threshold). Checking after every new user ends up declaring a winner in almost one case out of two (black curve) when there is none.Source : The Clever Machine (Dustin Stansbury), p-Hacking 101: Data Peeking

The Timing Problem for ML Models

Some models need time to show their true value. A personalized recommendation model may need several days to learn a new user's preferences. Testing for only 2 hours biases results in favor of the existing model (which already knows the users). Plan for a "warm-up" period in your experimental design.

Canary Deployment: Safety First

A/B testing typically sends 50% of traffic to the new model. Canary deployment is more cautious: it starts with a trickle.

  1. Deploy the new model, but send only 1-5% of traffic to it
  2. Monitor closely: is latency increasing? Is the error rate climbing? Are unexpected exceptions appearing?
  3. If everything is stable after a few hours, gradually increase: 10% → 25% → 50% → 100%
  4. If a problem occurs at any stage, immediate rollback to the old model

The canary doesn't try to prove that the new model is better (that's the A/B test's job). It tries to prove that it doesn't break anything.

Six panels labelled by deployment stage. In each one a router sends a percentage of traffic to a Blue Fleet and a Green Fleet, each holding four instances. Canary - Create: 100% to blue, green is empty. Canary - CanaryFlipTraffic: 75% to blue, 25% to green which now has one active instance. Canary - CanaryBake: same split, green is wrapped in an Alarms OK frame. Canary - FinalFlipTraffic: 100% to a now fully populated green. Canary - FinalBake: 100% to green inside the Alarms OK frame. Canary - Cleanup: the Blue Fleet is crossed out.
The canary stage by stage, as SageMaker implements it. Read left to right, then the second row: the new fleet (green) is created empty, takes a first slice of traffic, then goes through a baking phase where alarms must stay clear before it gets 100% of the traffic. The old fleet is only torn down at the very end, which keeps rollback available until then.Source : AWS SageMaker documentation, Canary Traffic Shifting
AspectA/B TestingCanary Deployment
GoalValidate business impactValidate technical stability
Typical durationDays to weeksA few hours to a day
Initial traffic50/501-5%
DecisionRigorous statistical analysisAutomatic thresholds (latency, errors)
Question"Is it better?""Does it break anything?"
In practice, combine both

The standard production workflow: first a canary (1-5% of traffic for a few hours) to validate that nothing breaks technically. Then, if the canary passes, launch an A/B test (50/50 for 1-2 weeks) to measure business impact. The canary protects you against bugs. The A/B test tells you if it's worth deploying.

Shadow Mode: Testing with Zero Risk

The new model runs in parallel with the production model, but its responses are never returned to users. Real traffic goes through both models, and you log both predictions to compare them afterward.

Two side-by-side panels. On the left, A/B Testing: a group of users is split into two subgroups joined by dashed lines; the first exchanges arrows in both directions with an Existing Model box, the second with a New Model box. On the right, Shadow Deployment: a single group of users exchanges arrows in both directions with the Existing Model box, while a plain grey arrow runs from the users to the greyed-out New Model box with no return arrow.
The whole difference lies in the direction of the arrows. In A/B testing, each group of users actually receives its model's answer. In shadow mode the new model does receive the requests, but no arrow runs back from it to the user: its predictions are only logged.Source : Towards Data Science, Building Better ML Systems, Chapter 4: Model Deployment and Beyond

Major advantage: zero risk to users. You see exactly where the new model diverges and can analyze problematic cases in detail before exposing anyone.

Drawbacks: you pay double in compute (two models run on every request). And most importantly, you learn nothing about real user engagement. The new model can predict perfectly in "simulation" and fail when it actually interacts with users (the user changes their behavior based on the response).

Blue/Green: The Instant Switch

You maintain two identical production environments: "blue" (current) and "green" (new). Traffic is entirely routed to one of them via a load balancer. The switch happens instantly: change the routing, and 100% of traffic goes to green.

Advantage: instant rollback. If things go wrong, switch back to blue in one second.

Drawback: no progressive validation. You go from 0% to 100% all at once. And you pay the infrastructure cost of two complete environments permanently.

Strategy Summary

StrategyRiskBusiness SignalInfra CostWhen to Use
Shadow ModeNoneNone (no real interaction)x2Before any deployment, to compare predictions
CanaryVery low (1-5%)Limited+5%Validate technical stability
A/B TestingModerate (50%)Strongx1Measure business impact
Blue/GreenHigh (100% at once)Immediatex2Switch with guaranteed rollback
A/B testing at industrial scale

Companies like Uber, LinkedIn, and Netflix run hundreds of A/B tests in parallel with dedicated infrastructure. Platforms like Statsig, LaunchDarkly, or Optimizely handle traffic routing, statistical calculations, and automatic anomaly detection. At this scale, tests are no longer done by hand.

Tools to Put It into Practice

  • Traffic routing: Istio, Envoy, AWS ALB to direct a precise percentage toward each model
  • Feature flags: LaunchDarkly, Unleash, Flagsmith to enable/disable a model without redeploying code
  • Statistical analysis: A/B testing frameworks calculate significance, statistical power, and confidence intervals. Don't do these calculations by hand.

Best Practices

  • Never 100% of traffic at once: always progressive, canary first, then A/B
  • Define rollback criteria in advance: "If P99 latency exceeds 500ms OR error rate exceeds 1%, automatic rollback." No discussion in the middle of a crisis.
  • Monitor continuously: a deployment without monitoring is like driving blindfolded. Real-time dashboard mandatory.
  • Automate rollback: if alert thresholds are breached, rollback should trigger automatically, without waiting for a human to wake up at 3 AM
  • Document every test: hypothesis, configuration, results, decision made. This is your logbook. In 6 months, when someone asks "why do we use this model?", the answer will be in the test documentation.

The best model in the world is worthless if it breaks production. Progressive rollout is just good engineering common sense applied to ML.

Check your understanding0 / 4

1. A recommendation model reaches 95% offline accuracy, but clicks collapse after deployment. What does this scenario reveal?

2. Two hours into an A/B test planned for two weeks, group B shows +5%. What should you do?

3. What is the real difference in purpose between a canary deployment and an A/B test?

4. Shadow mode runs the new model on real traffic without ever showing its answers. Why isn't that sufficient validation?