Sub topic 5
Choosing Metrics and Guardrails
Assume you can serve two model versions and understand basic metrics such as accuracy, precision, recall, and latency. This chapter focuses on deciding whether a candidate model is safe to expose to more production traffic.
Measure three kinds of outcomes
A rollout needs more than one metric. A model can improve prediction quality while making the service slower or harming a business outcome.
- System metrics measure whether the service works reliably. Examples include request error rate, timeout rate, p95 latency, CPU use, and memory use.
- Model metrics measure prediction behavior. Examples include precision, recall, calibration, prediction distribution, and the rate of rejected or uncertain predictions.
- Business metrics measure the result users or the organization care about. Examples include completed purchases, approved legitimate applications, fraud losses, or successful searches.
Use the stable model as the comparison baseline. Compare the candidate with the same time window, traffic population, and metric definition. An absolute error increase of 0.5 percentage points means something different when the baseline is 1% than when it is 20%.
| Metric type | Example guardrail | Typical response |
|---|---|---|
| System | Candidate p95 latency is no more than 10% above stable | Pause or roll back |
| Model | Candidate recall does not fall below the required floor | Pause or roll back |
| Business | Conversion does not fall by more than the allowed margin | Continue collecting data or stop |
Define guardrails before deployment
A guardrail is a rule that limits an unacceptable outcome. Set it before looking at candidate results. Otherwise, a team may unconsciously move the threshold after seeing an attractive result.
Use different responses for different violations:
- A hard guardrail stops promotion immediately. Examples include a safety failure, a high timeout rate, or a legal compliance violation.
- A soft guardrail pauses the rollout and requests investigation. Examples include a small latency increase or an uncertain business effect.
- An observation metric provides context but does not block rollout.
Each rule should specify a baseline, a threshold, a minimum amount of traffic, and an action. For example: “After at least 1,000 candidate requests, roll back if the error rate exceeds the stable rate by 0.5 percentage points.”
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 gate returns True because the candidate stays within both limits. Production systems should also check sample size, missing metrics, and important user segments. Missing data should usually fail closed rather than count as a passing result.
Check slices, not only averages
An overall average can hide harm to a smaller group. Break down metrics by relevant dimensions such as region, device type, language, account tier, or protected group. Define minimum sample sizes so that a tiny slice does not trigger a noisy rollback.
Monitor metric relationships as well. A fraud model with higher recall may also create too many false positives. A ranking model with higher clicks may reduce completed purchases. Guardrails should cover the trade-offs that matter for the product.
Use a promotion decision
A rollout controller can evaluate the candidate in stages. It should advance only when hard guardrails pass, enough data has accumulated, and no important slice shows a failure.
Exercise
Exercise
The candidate has lower error rate but 18% higher p95 latency, while the limit is 10%. Should the rollout advance?
Show answer
No. The latency guardrail fails, so pause or roll back even though the error rate improved.