Sub topic 10
Verifying that the rollback worked
A rollback is not finished when the command returns. This chapter covers how to confirm that traffic is served by the intended model version and that the service is healthy again. It also covers how to tell when the rollback has not fixed the problem.
This chapter assumes you can run kubectl against a Deployment and read basic Python. It also assumes you know the registry, alias and rollback-trigger concepts from earlier chapters and the usual service metrics (error rate, latency percentiles). The examples use the fraud-detector model from the registry chapter and a Deployment called model-server.
Why "the command succeeded" is not enough
Moving an alias or running kubectl rollout undo changes a desired state. Whether the running system matches that state is a separate question. These are common ways a rollback command succeeds while production stays broken:
- The serving process loaded the model at startup and never re-read the alias, so it still serves the bad version.
- Some replicas run the old version and some the new one during the rollout, and the bad replicas keep producing errors.
- A cache, such as a prediction cache or a feature cache, still holds outputs from the bad version.
- The rollback target has its own problem, for example a feature it expects no longer exists.
- The incident was not caused by the model at all, such as a broken upstream data source, so changing the version changes nothing.
Verification answers four questions, in order. Is the intended version deployed? Is it the one actually answering requests? Is the service healthy? Are the predictions sensible?
Layer 1: Check the deployment state
Start with the control plane. When the version is baked into the image or deployment spec, wait for the rollout to finish and then list what is actually running.
kubectl rollout status deployment/model-server --timeout=300s
kubectl get pods -l app=model-server \
-o custom-columns=NAME:.metadata.name,IMAGE:.spec.containers[0].image,READY:.status.containerStatuses[0].readyYou expect every pod to show the same image tag and true under READY. Treat these results as warnings:
- Two different image tags. The rollout is still in progress or is stuck, for example because new pods fail their readiness probe.
rollout statustimes out. The old ReplicaSet is probably still serving, and the Deployment is waiting on something. Inspect it withkubectl describe deployment/model-server.- A restart count that keeps rising. The rolled-back version may be crashing on startup.
If you use an alias instead, read it back from the registry. Do not assume the write worked.
from mlflow import MlflowClient
client = MlflowClient()
mv = client.get_model_version_by_alias("fraud-detector", "production")
print("Alias production ->", mv.version, "run:", mv.run_id)The registry only tells you what the alias says. It does not tell you what a running server has loaded. That takes the next layer.
Layer 2: Check which version is actually serving
The data plane is what users hit, so verify there. The most reliable method is for every prediction response to report the model version that produced it, either in the body or in a header such as X-Model-Version. This is worth building before you ever need a rollback. Without it you can only infer the serving version, and inference is the weakness here.
Sample enough responses to cover every replica. With a load balancer, 50 or more samples usually reaches all replicas of a small Deployment, but there is no guarantee. If you can, also check each pod directly through a port-forward or an internal status endpoint.
from collections import Counter
from itertools import chain, repeat
def sample_versions(predict, n=50):
"""Call predict() n times and count the model_version in each response."""
return Counter(predict()["model_version"] for _ in range(n))
def served_only(counts, expected):
"""True when every sampled response came from the expected version."""
return set(counts) == {expected}
# Fake client for a demonstration: the first 5 responses come from a
# replica that is still on version 4, the rest from version 3.
responses = chain(repeat({"model_version": "4"}, 5), repeat({"model_version": "3"}))
fake_predict = lambda: next(responses)
counts = sample_versions(fake_predict, n=50)
print(dict(counts)) # {'4': 5, '3': 45}
print(served_only(counts, "3")) # FalseIn real use, replace fake_predict with a function that sends a test request to the service and parses the version. A result like the one above means a replica was not rolled back. The service is not recovered, even if aggregate metrics look better.
Two details matter here:
- Send the sample through the same path production traffic uses, such as the ingress or service mesh. Calling a single pod directly can hide a routing rule that still sends part of the traffic to the bad version.
- Check batch and streaming consumers separately. A scheduled batch job may load the model once per run, so it keeps the bad version until its next start.
Layer 3: Check service health against a baseline
Once the right version is serving, check that the symptoms that triggered the rollback have gone. Compare against a baseline: the known-good period before the bad release, or the stable version's own numbers. Use the same metrics and thresholds you used to define the trigger, so "recovered" means the same thing as "broken" did.
The main metrics are:
- Error rate (5xx and timeouts).
- Latency at p95 and p99.
- Saturation, such as CPU, memory and queue depth.
- Request volume, to confirm that traffic is flowing and the error rate is not low only because clients have stopped calling.
Metrics lag. Dashboards often aggregate over one to five minutes, and a rate over a window still includes the bad period. Look only at data from after the rollback finished. Wait until the window holds enough requests to be meaningful, because a rate computed from 12 requests is noise.
Layer 4: Check prediction quality
Healthy infrastructure does not imply good predictions. The old version can respond quickly and still be wrong, for instance if it was trained on data that no longer matches the world. Accuracy needs labels, and labels often arrive hours or weeks later, so verify with proxies right away and confirm with labels later.
Useful proxies:
- The distribution of prediction scores or classes. For a fraud model, the share of requests flagged should return close to its pre-incident range.
- Input feature statistics, such as null rates and value ranges. If these look wrong, the cause may be upstream and a rollback will not help.
- Downstream business signals, such as the approval rate, the review queue size or the click-through rate.
- A fixed set of golden requests with known expected outputs, sent after the rollback. These catch gross failures such as a wrong preprocessing step.
The script below combines these checks. It takes a window of post-rollback measurements, a baseline and limits, and returns a list of failures instead of a bare True or False, so a person can see why verification failed.
def verify_recovery(window, baseline, limits):
"""Compare post-rollback metrics with a baseline. Return a list of failures."""
failures = []
if window["requests"] < limits["min_requests"]:
failures.append(
f"only {window['requests']} requests, need {limits['min_requests']}"
)
return failures # not enough data to judge anything else
if window["error_rate"] > baseline["error_rate"] + limits["max_error_increase"]:
failures.append(
f"error rate {window['error_rate']:.3f} vs baseline {baseline['error_rate']:.3f}"
)
if window["p95_ms"] > limits["p95_limit_ms"]:
failures.append(f"p95 {window['p95_ms']} ms over limit {limits['p95_limit_ms']} ms")
if abs(window["flag_rate"] - baseline["flag_rate"]) > limits["max_flag_rate_shift"]:
failures.append(
f"flag rate {window['flag_rate']:.3f} vs baseline {baseline['flag_rate']:.3f}"
)
return failures
baseline = {"error_rate": 0.010, "flag_rate": 0.040}
limits = {
"min_requests": 500,
"max_error_increase": 0.005,
"p95_limit_ms": 250,
"max_flag_rate_shift": 0.010,
}
post_rollback = {"requests": 2400, "error_rate": 0.011, "p95_ms": 190, "flag_rate": 0.043}
print(verify_recovery(post_rollback, baseline, limits) or "recovered")
still_bad = {"requests": 2400, "error_rate": 0.011, "p95_ms": 190, "flag_rate": 0.110}
print(verify_recovery(still_bad, baseline, limits))The first call prints recovered. The second prints one failure about the flag rate. Latency and errors look fine there, but the model's output distribution has not returned to normal, which is exactly the case a health-only check misses.
Use a stabilization window
A single good reading does not prove recovery. Define a stabilization window, a period in which all checks must keep passing before you close the incident. A typical choice is 15 to 60 minutes for service metrics. Choose a longer period for anything that follows daily cycles, because traffic patterns at midday differ from those at night.
Some problems only appear later. A cache can expire, a batch job can run, or a slow memory leak can accumulate in the rolled-back version. Record the time the rollback finished and the time the window ends, so the status of the incident is not a matter of impression.
Common mistakes
| Mistake | Consequence | Fix |
|---|---|---|
| Checking only the registry alias | Servers that cached the old model still serve it | Check the version reported in live responses |
| Sampling from one pod | Mixed versions go unnoticed | Sample through the production path and check each pod |
| Reading metrics that include the incident period | Recovery looks slower or faster than it is | Query only data after the rollback completed |
| Judging from a handful of requests | Random noise looks like a trend | Require a minimum request count |
| Using different thresholds than the trigger | Disagreement about whether it is fixed | Reuse the trigger metrics and thresholds |
| Closing immediately | Late failures are missed | Hold a stabilization window |
What to record
When verification passes, write down the evidence in the incident notes: the version before and after, the time the rollback finished, the sampled version counts, the before and after metric values, and when the stabilization window ended. This record feeds the post-incident review in a later chapter and shows other people that the incident is closed because evidence says so.
Exercise
After running kubectl rollout undo, kubectl rollout status reports success and the registry alias reads version 3. Error rate has dropped. Sampling 50 prediction responses shows 44 from version 3 and 6 from version 4. What should you conclude, and what do you do next?
Show answer
The rollback is not complete. The control-plane checks passed, but the data plane shows that something still serves version 4, which can be a replica that cached the old model, a route that bypasses the rollback, or a separate consumer such as a batch job. The lower error rate comes from the 88% of traffic that now reaches version 3, so it does not prove recovery. Find which pod, route or consumer returns version 4 (check each pod's image and the routing rules), restart or fix it, then re-sample until all responses report version 3. Then start the stabilization window.