Sub topic 5
Defining Rollback Triggers and Thresholds
This chapter assumes you can read basic Python and know what error rate, latency percentiles, and accuracy mean. It also assumes you have seen a model served behind an HTTP endpoint on a platform such as Kubernetes. The previous chapter covered the signals that show a model version is unhealthy. This chapter turns those signals into explicit rules that say when to roll back.
What a rollback trigger is
A rollback trigger is a rule that compares a live measurement with a limit and answers one question: should we return to the previous version now? A trigger has four parts.
- A signal, such as the 5xx error rate or the p95 latency.
- A comparison, either against a fixed limit or against a baseline.
- A window, which is the span of time or the number of requests the signal is measured over.
- An action, such as page a person, halt the rollout, or move the alias back.
Without a written trigger, the decision to roll back happens in a chat thread during an incident. People disagree about whether a dip is real, and the delay is the real cost. A trigger agreed on before the release turns that argument into a lookup.
Choosing signals
Triggers fall into three groups. Each group has a different speed and a different reliability.
| Group | Examples | Available | Typical use |
|---|---|---|---|
| Service health | 5xx rate, timeouts, p95/p99 latency, memory, restarts | Seconds | Automatic trigger |
| Prediction behavior | Score distribution shift, share of positive predictions, null or default outputs | Minutes | Alert, sometimes automatic |
| Model quality | Accuracy, precision, recall, business conversion | Hours to weeks, depending on label delay | Human decision, or automatic only with proxies |
Service health signals are fast and unambiguous. A crashing container is not a matter of opinion. Quality signals matter most, but they depend on ground truth labels. In fraud detection, labels may arrive after a chargeback, weeks later. You cannot wait that long to notice that a new model flags every transaction.
Prediction behavior signals fill this gap. They need no labels, so they react within minutes. If the previous model approved 96% of requests and the new one approves 60%, something is wrong even though you cannot yet prove which model is more accurate.
Absolute and relative thresholds
There are two ways to set a limit.
An absolute threshold is a fixed number, for example "p95 latency above 250 ms". It suits limits that come from outside the model: a service level objective (SLO), a timeout set by a caller, or a contract. Absolute thresholds do not drift, but they do not adapt when traffic changes. A latency limit that is fine at midday can be too tight at a daily peak.
A relative threshold compares the new version with a baseline. The baseline is the previous version's behavior, ideally measured at the same time on the same traffic. For example, "error rate more than 2 percentage points above the baseline". Relative thresholds cancel out traffic changes, because both versions see the same load. They suit quality and behavior signals, where the right absolute value is unknown.
The example from the topic combines both:
def should_roll_back(error_rate, baseline_error_rate, p95_ms, p95_limit_ms,
max_error_increase=0.02):
"""Return True when the new version breaches an agreed threshold."""
error_regressed = (error_rate - baseline_error_rate) > max_error_increase
too_slow = p95_ms > p95_limit_ms
return error_regressed or too_slow
print(should_roll_back(error_rate=0.07, baseline_error_rate=0.03,
p95_ms=180, p95_limit_ms=250))The error rate rose by 4 points, which is more than the allowed 2, so the function prints True. Latency is within its limit, but the rule uses or, so one breach is enough. Notice that the error check is relative and the latency check is absolute. That is deliberate: the latency limit comes from an SLO, while the right error rate depends on the model and the traffic.
Windows, sample size, and noise
A threshold with no window triggers on noise. One slow request can push a p99 over the limit. If you roll back on every blip, you will spend your time rolling back healthy releases, and people will learn to ignore the alerts.
Three controls reduce false triggers.
- Evaluation window. Require the breach to hold over a span, such as five minutes, rather than at one instant. Prometheus alerting rules express this with a
for:duration. - Minimum sample size. A rate computed from 20 requests is unreliable. If the new version has served 20 requests and 2 failed, the error rate is 10%, but that tells you little. Require a minimum count, such as 500 requests, before the rule is allowed to fire.
- Consecutive breaches. Require the check to fail several evaluations in a row. This filters isolated spikes while still reacting within minutes.
The effect of sample size is easy to see in a small extension of the earlier function:
def should_roll_back_windowed(window, baseline_error_rate, p95_limit_ms,
max_error_increase=0.02, min_requests=500,
consecutive=3):
"""window is a list of dicts, oldest first, one per evaluation interval.
Each dict has: requests, errors, p95_ms.
Roll back only if the last `consecutive` intervals all breach
and each had enough traffic to be meaningful.
"""
if len(window) < consecutive:
return False
recent = window[-consecutive:]
for interval in recent:
if interval["requests"] < min_requests:
return False
error_rate = interval["errors"] / interval["requests"]
regressed = (error_rate - baseline_error_rate) > max_error_increase
too_slow = interval["p95_ms"] > p95_limit_ms
if not (regressed or too_slow):
return False
return True
history = [
{"requests": 800, "errors": 20, "p95_ms": 190},
{"requests": 820, "errors": 70, "p95_ms": 200},
{"requests": 790, "errors": 75, "p95_ms": 210},
{"requests": 810, "errors": 80, "p95_ms": 205},
]
print(should_roll_back_windowed(history, baseline_error_rate=0.03,
p95_limit_ms=250))The first interval is healthy at 2.5% errors, but the last three show roughly 8.5% to 9.9%, each more than 2 points over the 3% baseline, so the function prints True. If any of the last three intervals had fewer than 500 requests, it would return False instead. That is the safe default for low traffic, but it creates its own risk: a version that receives little traffic may never accumulate enough data. Handle that case with a time limit, so a rollout that has not reached the minimum sample within a set period is held for human review.
Severity tiers
Not every breach deserves the same response. Define tiers so that the action matches the damage.
| Tier | Example condition | Action |
|---|---|---|
| Critical | 5xx rate above 5%, or p95 above twice the limit | Roll back immediately, then notify |
| Major | Error rate more than 2 points above baseline for 5 minutes | Roll back, or page on-call with a rollback ready |
| Minor | Score distribution drift above a set distance for 30 minutes | Open a ticket, investigate, keep serving |
Critical conditions justify automatic action because the cost of waiting is high and the cost of a needless rollback is low. Rolling back to a version that was healthy yesterday is rarely harmful. The minor tier shows the opposite case. Drift can come from a real change in the world, such as a holiday sale, and rolling back would not fix that.
Guardrails and the baseline problem
Relative thresholds are only as good as the baseline. Several problems come up in practice.
- Mismatched traffic. If the new version serves a canary slice and the baseline is the whole fleet's daily average, differences in traffic mix look like model regressions. Compare the two versions over the same period and, where possible, over the same kind of requests.
- Stale baseline. A baseline taken last month may not describe today's data. Recompute it from the currently serving version.
- Baseline already unhealthy. If the old version was itself degrading, a relative rule will not fire, because the new version looks no worse. Keep a small set of absolute limits as a floor.
- Delayed labels. Quality metrics computed from labels describe requests from days ago, not the current release. Treat them as confirmation, and label the dashboard with the data's age.
A good set of triggers mixes the two kinds: absolute limits for service health, relative limits for behavior and quality, and a floor that catches the case where both versions are bad.
Writing triggers down
Store the rules next to the model's release configuration, in version control, so they are reviewed like code. A short declarative file is enough:
ROLLBACK_POLICY = {
"model": "fraud-detector",
"baseline_alias": "production",
"window_minutes": 5,
"min_requests": 500,
"consecutive_breaches": 3,
"rules": [
{"signal": "http_5xx_rate", "kind": "absolute",
"limit": 0.05, "tier": "critical"},
{"signal": "p95_latency_ms", "kind": "absolute",
"limit": 250, "tier": "critical"},
{"signal": "error_rate", "kind": "relative",
"max_increase": 0.02, "tier": "major"},
{"signal": "approval_rate", "kind": "relative",
"max_abs_change": 0.10, "tier": "major"},
],
}
for rule in ROLLBACK_POLICY["rules"]:
print(rule["tier"], rule["signal"], rule["kind"])Each rule names its tier, so the code that evaluates the policy can decide whether to roll back or to page. Reviewing a pull request that changes max_increase from 0.02 to 0.10 makes the loosening visible, which is the point.
Common errors
- Triggering on a single metric. A model can have good latency and badly wrong predictions. Pair a health signal with a behavior signal.
- Thresholds nobody tested. If you never run the rule against past data, you do not know its false positive rate.
- No minimum sample. Early in a canary, tiny counts produce extreme rates in both directions.
- Only quality metrics with long label delay. The trigger exists on paper but fires after the damage is done.
- Rolling back for drift that is not the model's fault. Input drift caused by upstream data changes will follow you to the old version. Check whether the baseline version shows the same shift before acting.
- Triggers that cannot be acted on. A rule is only useful if the rollback it calls for is possible, which depends on the old version being compatible with current features. That is covered in the compatibility chapter.
Exercise
A new model version has served 120 requests in a canary and 9 failed, a 7.5% error rate against a 3% baseline with a maximum allowed increase of 2 points. Your policy requires at least 500 requests and 3 consecutive breaching intervals. Should the policy roll back now? What would you do instead, and why?
Show answer
No, the policy should not fire yet. With only 120 requests, the sample is below the 500-request minimum, so the error rate is too noisy to trust, and the consecutive-breach requirement is not met either. Hold the rollout at its current traffic share, keep collecting data, and set a time limit after which a person reviews it if the sample stays small. If the failures are 5xx errors from a crash rather than prediction errors, a critical absolute rule on the 5xx rate could justify acting sooner, because service health failures are unambiguous and cheap to undo.
Exercise
Your team's only trigger is "accuracy drops more than 3 points below baseline", computed from labels that arrive two weeks after prediction. Name two problems with this design and suggest one added trigger for each.
Show answer
First, the trigger is too slow: a bad model could serve for two weeks before it fires. Add a service health rule (for example 5xx rate or p95 latency) and a label-free behavior rule (for example the share of positive predictions compared with the baseline over the same window). Second, a quality-only trigger gives no protection against crashes or timeouts, which cause immediate harm and show up in service health metrics within seconds. The absolute 5xx and latency limits cover that case.