Sub topic 14
Choosing and combining strategies
This chapter assumes you know how shadow, canary, and A/B rollouts work individually. It also assumes you can read short Python snippets and know what a p-value and a guardrail metric are. Here you will decide which strategy fits a given model change and how to chain strategies so each one removes a different risk.
Each strategy answers a different question
The three strategies are not ranked from weak to strong. Each answers a different question, and that question determines when you need it.
| Strategy | Who sees the candidate's output | Question it answers | Main cost |
|---|---|---|---|
| Shadow | Nobody. Output is only logged. | Does the candidate run correctly on real inputs, and how does it differ from stable? | Double compute, and no user-outcome data |
| Canary | A small, growing share of users | Is it safe to serve to users, in terms of errors, latency, and guardrails? | Some users are exposed to any defect |
| A/B test | A planned share of users, held fixed | Does it improve a business outcome, with statistical confidence? | Time, traffic, and discipline about the analysis |
Shadow cannot tell you whether users benefit, because they never see the output. A canary usually has too little traffic and too short a duration to detect a small business effect. An A/B test is a poor first exposure because it commits a large share of users for days or weeks before you know the model is operationally sound.
Criteria for choosing
Work through these factors for each change. Several often apply at once.
- Blast radius of a wrong answer. A bad movie recommendation is cheap. A wrong fraud block or credit decision is not. The higher the cost, the more you want shadow before any user exposure, and the smaller the first canary step.
- Side effects. Shadow sends real requests to the candidate. If the candidate's call triggers an email, a write, or a charge, shadowing it duplicates that action. Either stub the side effects or replay logged requests offline instead.
- Change in the output contract. If the candidate returns a new schema, new score scale, or different thresholds, downstream consumers can break. Shadow with output comparison finds this before users do.
- Label delay. If outcomes arrive after 30 days, as in loan defaults, an A/B test on the true outcome is slow. You will likely rely on proxy metrics, which carry their own risk, or accept a long experiment.
- Traffic volume. The sample size needed to detect an effect may exceed what your traffic delivers in an acceptable time. Check this before committing to an A/B test.
- Cost of running two models. Shadow doubles inference load for its duration. For large models, shadow a sampled fraction of requests.
- Reversibility. If rollback is one config change and the effect is easy to observe, a canary alone is often enough. If harm persists after rollback, as with emailed users or changed account states, be more conservative.
- What you need to claim. "It does not break anything" needs only shadow and canary. "It increases conversion" needs an A/B test.
A default pipeline
For a meaningful model change, the usual chain is offline evaluation, then shadow, then canary, then A/B test, then full rollout. Each stage is a gate with its own exit criteria, and a failure at any stage returns to development.
The shortcut from canary to full rollout matters. Many changes need no A/B test: a retrained model on fresh data with the same architecture, a latency optimization, or a model distilled to match the old outputs. For those, the canary's guardrails are the whole decision.
A/B tests are also not always preceded by a separate canary. If the first step of the experiment is small, such as 1% for a day, it serves as the canary. What matters is that guardrails are monitored from the first request, with automatic rollback, even while the experiment is nominally "just collecting data."
Combining strategies in practice
Stages overlap in useful ways:
- Shadow feeds the canary's thresholds. Shadow gives you the candidate's real latency distribution and its disagreement rate with stable. Use these to set canary guardrails instead of guessing.
- Canary and A/B share the router. The same sticky, hash-based assignment can serve both. A canary is an assignment with a ramp schedule and tight guardrails. An experiment is an assignment with a fixed split and a pre-registered analysis. Keep the experiment salt separate from the ramp's, or the experiment's randomization will be correlated with who was in the canary.
- Guardrails run everywhere. The same system and model-health checks should gate every stage, so a stage-specific oversight cannot hide a regression.
- Shadow can continue under a canary. Running a second candidate in shadow while the first is in canary lets you queue the next iteration without exposing users.
Worked scenarios
Retrained fraud model, same features, same schema. The risk is operational and decision quality, and labels (chargebacks) arrive weeks later. Do offline evaluation, shadow for a few days to compare decisions and latency, then a staged canary with guardrails on block rate and error rate. A chargeback-based A/B test would take too long for a routine retrain, so you would skip it and monitor delayed labels after promotion.
New ranking model that changes what users see. Offline metrics are weak proxies for engagement. Do a short shadow for contract and latency, a quick canary at 1% to 5%, then a full A/B test on click-through or conversion with a pre-computed sample size.
Model that triggers actions, such as sending a notification. Do not shadow against live side effects. Replay logged requests through the candidate with side effects stubbed, then go to a small canary with strict guardrails on action volume.
A planning helper
Writing the decision down as code forces you to state your assumptions. The sketch below turns the criteria above into a plan and checks whether an A/B test is feasible with your traffic.
from dataclasses import dataclass
from math import ceil
from statistics import NormalDist
def required_n_per_arm(p: float, mde_abs: float,
alpha: float = 0.05, power: float = 0.8) -> int:
"""Approximate sample size per arm for a two-sided two-proportion test."""
z_alpha = NormalDist().inv_cdf(1 - alpha / 2)
z_power = NormalDist().inv_cdf(power)
return ceil(2 * p * (1 - p) * (z_alpha + z_power) ** 2 / mde_abs ** 2)
@dataclass
class Change:
has_side_effects: bool
output_contract_changed: bool
needs_business_claim: bool
baseline_rate: float
min_detectable_effect: float
daily_eligible_units: int
max_experiment_days: int = 28
def rollout_plan(c: Change) -> list[str]:
steps = ["offline evaluation"]
if c.has_side_effects:
steps.append("replay logged requests with side effects stubbed")
else:
steps.append("shadow deployment")
steps.append("canary with guardrails")
if c.needs_business_claim:
n = required_n_per_arm(c.baseline_rate, c.min_detectable_effect)
days = ceil(n / (c.daily_eligible_units * 0.5)) # 50/50 split
if days <= c.max_experiment_days:
steps.append(f"A/B test: {n} units per arm, about {days} days")
else:
steps.append(
f"A/B test infeasible: needs {days} days; "
"raise the minimum detectable effect or use a proxy metric"
)
steps.append("full rollout")
return steps
change = Change(
has_side_effects=False,
output_contract_changed=False,
needs_business_claim=True,
baseline_rate=0.048,
min_detectable_effect=0.006,
daily_eligible_units=8000,
)
for step in rollout_plan(change):
print("-", step)With a 4.8% baseline and a 0.6 percentage point effect, each arm needs roughly 20,000 units. At 8,000 eligible units per day split evenly, that is about five days, so the experiment is feasible. Halve the traffic or the effect size and the answer changes quickly, which is why you check before committing.
Common mistakes
- Treating a clean canary as proof of improvement. A canary shows the candidate did no harm at small scale. It does not show the candidate is better.
- Skipping shadow because the canary is "small." A defect that crashes or returns malformed output still reaches real users in the canary. Shadow finds it for free.
- Running every strategy for every change. A full pipeline for a config tweak wastes time, and teams then start skipping stages for everything. Match the pipeline to the risk.
- Changing criteria mid-stage. Decide gate thresholds and the experiment's primary metric before starting. Otherwise you will tune them to the result you wanted.
- No rollback path at each stage. A stage without a tested, fast revert is not a safe stage.
Exercise
A team replaces a spam classifier with a retrained version. The architecture, features, and output schema are unchanged. Messages are labeled by user reports within an hour. Traffic is high, and rolling back is a single config change. They want to claim a lower false-negative rate. Which stages would you choose, and which would you skip?
Show answer
Use offline evaluation, a short shadow run to compare decisions and latency, and a staged canary with guardrails on error rate, latency, and the share of messages flagged. Because labels arrive within an hour and traffic is high, a short A/B test on the user-report rate is cheap and is the right way to support the false-negative claim, so include it. Skipping the A/B test would leave the claim supported only by offline numbers. A long shadow period is not needed, since the contract is unchanged and rollback is trivial.