Sub topic 8
Deciding to promote or roll back
This chapter assumes you can read short Python and YAML snippets, know common model metrics such as precision, recall, and latency, and understand proportions and averages. You should also know how a canary release sends a small share of traffic to a candidate model, as covered in the previous chapter.
A canary only protects you if you decide ahead of time what "good enough to continue" and "bad enough to stop" mean. Without written criteria, teams argue about dashboards while users are affected. This chapter shows how to turn promotion and rollback into explicit rules that a script can check.
Promotion and rollback are decisions with different costs
Promotion means moving the candidate to a larger share of traffic, and eventually to 100%. Rollback means returning all traffic to the stable model. The two errors are not equal:
- Promoting a bad model exposes more users to harm.
- Rolling back a good model wastes engineering time and delays the benefit.
Most teams accept more false rollbacks than false promotions, so the rules lean toward caution. Rollback should also be cheap and fast. If it takes a code change and a full deployment, people hesitate to use it.
Write the criteria before the rollout starts
Decide the rules before you see any canary data. Rules written after the fact tend to fit whatever the data shows. A useful rule set has three parts.
- Hard rollback triggers. Conditions that stop the canary at once, such as an error rate far above stable or a crash loop.
- Promotion gates. Conditions that must hold for a minimum time and sample size before moving to the next stage.
- Hold conditions. Cases where neither promotion nor rollback is justified, such as too little traffic to judge.
The third part is easy to forget. Many canary tools only know "advance" and "abort". A real rollout often needs "wait".
Use guardrails that match the failure modes
Guardrail metrics come from three layers, as described in the metrics chapter. The table shows how each layer behaves during a canary.
| Layer | Example metric | Signal speed | Typical use |
|---|---|---|---|
| System | Error rate, p95 latency, memory | Seconds to minutes | Hard rollback trigger |
| Model | Score distribution, prediction rate, agreement with stable | Minutes to hours | Promotion gate |
| Business | Conversion, chargeback rate, complaints | Hours to weeks | Final promotion decision |
Fast metrics catch crashes and slowdowns. Slow metrics catch quality problems. A canary that lasts only an hour can prove the model is not broken, but it cannot prove the model is better.
A canary gate in code
The gate below compares candidate and stable metrics against two thresholds: an allowed increase in error rate and an allowed ratio for p95 latency (the latency that 95% of requests stay under).
def canary_gate(stable: dict, candidate: dict,
max_error_increase: float = 0.005,
max_latency_ratio: float = 1.10) -> bool:
error_ok = candidate["error_rate"] <= stable["error_rate"] + max_error_increase
latency_ok = candidate["p95_latency_ms"] <= stable["p95_latency_ms"] * max_latency_ratio
return error_ok and latency_ok
stable = {"error_rate": 0.002, "p95_latency_ms": 120}
candidate = {"error_rate": 0.003, "p95_latency_ms": 128}
print(canary_gate(stable, candidate))This prints True. The candidate's error rate is 0.001 above stable, within the 0.005 allowance. Its latency is 128 ms against a limit of 132 ms.
The function returns only a boolean, so it cannot express "wait". It also ignores sample size. With 40 requests in the canary, one failure moves the error rate by 2.5 percentage points. A production gate should return one of three values and check volume first.
from enum import Enum
class Decision(Enum):
PROMOTE = "promote"
HOLD = "hold"
ROLLBACK = "rollback"
def decide(stable: dict, candidate: dict,
min_requests: int = 2000,
rollback_error_increase: float = 0.02,
max_error_increase: float = 0.005,
max_latency_ratio: float = 1.10) -> Decision:
# Hard trigger: act even on a small sample if the failure is large.
if candidate["error_rate"] > stable["error_rate"] + rollback_error_increase:
return Decision.ROLLBACK
# Not enough data to judge the finer thresholds.
if candidate["requests"] < min_requests:
return Decision.HOLD
error_ok = candidate["error_rate"] <= stable["error_rate"] + max_error_increase
latency_ok = candidate["p95_latency_ms"] <= stable["p95_latency_ms"] * max_latency_ratio
return Decision.PROMOTE if error_ok and latency_ok else Decision.ROLLBACK
stable = {"error_rate": 0.002, "p95_latency_ms": 120, "requests": 95000}
candidate = {"error_rate": 0.003, "p95_latency_ms": 128, "requests": 5000}
print(decide(stable, candidate).value)This prints promote. If candidate["requests"] were 500, it would print hold. If the candidate error rate were 0.05, it would print rollback regardless of volume.
Stages and soak time
A staged canary moves through fixed traffic shares, with a minimum wait at each stage. The wait is called soak time. It matters because some problems appear only over time, such as memory leaks, cache warm-up effects, or daily traffic patterns.
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: fraud-model
spec:
hosts:
- fraud-model
http:
- route:
- destination:
host: fraud-model
subset: stable
weight: 95
- destination:
host: fraud-model
subset: candidate
weight: 5This manifest is stage one: 5% to the candidate. Later stages change the weights to 90/10, 75/25, 50/50, and then 0/100. The subsets stable and candidate must exist in a matching DestinationRule.
Choose soak time to cover the cycles in your traffic. If demand differs between weekdays and weekends, a 30-minute soak at the first stage will not reveal a weekend-only problem. Many teams run the final stage for at least one full daily cycle.
Compare against stable at the same time
Always compare the candidate with the stable model running at the same time, not with last week's numbers. Traffic mix, holidays, and upstream outages change metrics for both models. A concurrent comparison cancels these shared effects.
Two details matter here:
- Compare the same request mix. If routing is not random, for example if the canary serves only one region, differences may come from the region and not the model.
- Compare a normalized quantity. Use rates and percentiles, not raw counts, because the canary gets far less traffic.
Slow signals and delayed labels
Business and accuracy metrics often depend on labels that arrive late. A fraud model may not learn the true outcome of a transaction for 30 days. You cannot hold a canary that long at every stage.
Common approaches:
- Gate early stages on system metrics and model proxies, such as score distribution shift and agreement with the stable model.
- Keep the canary small while labels accumulate, so limited exposure caps the harm.
- Make the final promotion depend on the matured business metric, and say so in the plan.
Be explicit about which decision each metric supports. A proxy that looks fine does not prove the label-based metric will look fine.
Rolling back well
A rollback is only useful if it works under pressure. Check these points before you start a canary.
- One-step action. Set the candidate weight to 0, or flip a flag. Do not require a rebuild.
- Keep the stable model warm. Stable stays deployed and loaded until the candidate is fully promoted and has passed a final observation period. Otherwise rollback includes a cold start.
- Automate the hard triggers. A human should not have to notice a 10x error spike. Alerts can call the rollback directly.
- Check compatibility. If the candidate writes features, caches, or state that the stable model reads, rolling back may leave bad data behind. Version these artifacts.
- Record the reason. Save the metrics and the decision. This helps later when someone asks why a model was blocked.
Common errors
- Changing thresholds mid-rollout. This turns the gate into a justification step. If a threshold is wrong, roll back, fix the plan, and restart.
- Judging on too little data. Small canaries have noisy metrics. Use a minimum sample size and a hold state.
- Looking at averages only. An average latency can stay flat while p95 rises. Use percentiles for latency.
- Ignoring segments. A candidate may be better overall and worse for a small group, such as new users. Check key segments, and decide in advance which ones can block promotion.
- Promoting without a final observation period. Keep stable available after reaching 100%, then retire it after the period ends.
- Treating a canary as an A/B test. A canary gate checks for harm. It does not give you a measured gain in a business outcome. The A/B chapters cover that question.
Summary of the decision rules
| Situation | Decision | Reason |
|---|---|---|
| Error rate far above stable, any sample size | Roll back | Large harm is visible quickly |
| Too few requests or soak time not met | Hold | Metrics are too noisy to trust |
| Guardrails pass at volume and time | Promote to next stage | No evidence of harm |
| Guardrails fail at volume and time | Roll back | Evidence of harm |
| All stages pass, final observation done | Full promotion | Stable can be retired |
Exercise
A candidate model has 600 requests in its canary stage, where your plan requires 2000. Its error rate is 0.4 percentage points above stable, and your hard rollback trigger is 2 points above. Using the decide function in this chapter, what is the decision, and why would returning only a boolean be a problem here?
Show answer
The decision is HOLD. The error increase is below the 2-point hard trigger, so no rollback happens, and 600 requests is below the 2000 minimum, so the finer thresholds are not checked. A boolean gate would have to answer yes or no. Answering yes would promote on too little data, and answering no would roll back a model that may be fine. A three-state result lets the rollout wait for more traffic.
Exercise
Your fraud model's true labels arrive after 30 days. Describe how you would structure promotion criteria across stages.
Show answer
Gate the early stages on fast signals: system metrics such as error rate and p95 latency, plus model proxies such as score distribution and agreement with stable. Keep the canary share small while labels accumulate, so exposure limits any harm. Make the final promotion to 100% depend on the matured label-based metric, such as the chargeback rate, and state this in the plan before the rollout begins. Keep the stable model deployed until that decision is made.