Sub topic 8
Deciding between rollback and roll forward
This chapter assumes you know how a model is packaged and served, you have used Kubernetes Deployments or a similar platform, and you can read basic Python. It also assumes you have read the earlier chapters on versioned artifacts, the model registry, deployment pointers, monitoring signals, and rollback triggers. Here you will learn how to choose between two recovery paths once a trigger has fired.
Two ways out of an incident
When a new model version misbehaves in production, you have two basic options.
- Rollback returns production to a version that was already running and was known to be good. You change a pointer or redeploy an old artifact. No new code or model is built.
- Roll forward ships a new version that fixes the problem. That might be a patched preprocessing step, a corrected configuration, a retrained model, or a hotfix to the serving code.
Both end with a healthy service. They differ in speed, risk, and what they teach you. Rollback is usually faster and more predictable. Roll forward is sometimes the only option that works.
The default for ML systems is to roll back first and investigate afterward. This is not because rollback is always right. It is because stopping the damage is the first job, and a rollback is a rehearsed, low-variance action. A fix is new, untested work being done under pressure.
Why rollback is the default
A rollback has three properties that make it attractive during an incident.
- The target is known. The old version served real traffic before. Its latency, memory use, and error profile are on record.
- The change is small. With a registry alias, it is one pointer move. With Kubernetes, it is one
rollout undo. - It needs no diagnosis. You do not have to understand the root cause to restore the previous behavior.
A roll-forward fix has the opposite profile. The target is new, the change may touch several components, and it requires you to have already found the cause. If your diagnosis is wrong, you have extended the incident and added a second unknown version to production.
When rollback is not safe or not enough
Rollback assumes the old version still fits the system. Several situations break that assumption. Each one should push you toward roll forward, or toward a rollback plus extra work.
The data or schema has moved on
Suppose version 5 introduced a new feature column, and the feature pipeline now writes only the new schema. Version 4 expects the old columns. Rolling back to version 4 would produce missing-feature errors or, worse, silently wrong predictions. If the old version cannot read today's inputs, rollback is not available until the inputs are restored or adapted.
Downstream consumers have adapted
Another service may have started depending on a new output field, a new score range, or a recalibrated probability. After the rollback, those consumers receive the old format. A threshold tuned to version 5's scores may now let through too many or too few cases.
State was written by the new version
Some models write state: embeddings stored in a vector index, cached predictions, feature-store entries computed by the model, or labels fed to a retraining loop. Records created by version 5 may be incompatible with version 4. Rolling back the model does not roll back that state.
The old version is itself broken
The previous version may have been fine when it was deployed and be wrong now. This happens when the world has drifted since then, when an upstream data source changed, or when a dependency such as a library, a tokenizer, or a certificate expired. If the old version would also fail today, rolling back only changes which failure you have.
The problem is not in the model
If the cause is a bad feature pipeline, a broken upstream data feed, or an infrastructure fault, then both versions are affected. Rolling back the model fixes nothing. Check this before you act. A useful test is to compare the new version against the baseline on the same traffic, as a canary or shadow deployment would show. If both degrade together, the model version is not the cause.
A security or compliance defect is in the old version too
If the incident is a leaked-data problem, a licensing issue, or a vulnerability that exists in earlier artifacts, returning to an old version may reintroduce the exposure.
A decision checklist
Work through these questions in order. Stop at the first answer that settles it.
| Question | If yes | If no |
|---|---|---|
| Is the damage ongoing and serious (wrong decisions, outage, harm to users)? | Mitigate now. Continue to the next questions to pick how. | You have time to consider a fix, but still check the rest. |
| Did the problem start when the new version took traffic? | The version is a likely cause. Continue. | Suspect data, infrastructure, or drift. Do not roll back yet. |
| Is there a known-good earlier version that is still available in the registry or image repository? | Continue. | Roll forward, or fall back to a rules-based or default behavior. |
| Is that version compatible with current features, preprocessing, and consumers? | Rollback is viable. | Fix the compatibility gap, or roll forward. |
| Is the old version free of the same defect and of security issues? | Rollback. | Roll forward, or use a safe fallback. |
| Is a verified fix already available and cheaper to deploy than a rollback? | Roll forward may be reasonable. | Roll back. |
The last row is rare. A fix is almost never ready at the moment an incident is declared.
Encoding the decision
You can write the checklist as a function so it is reviewed, tested, and shared. This does not replace human judgment. It makes the reasoning visible, and it gives an on-call engineer a starting recommendation.
from dataclasses import dataclass
@dataclass
class IncidentFacts:
started_with_new_version: bool
known_good_available: bool
compatible_with_current_system: bool
old_version_has_same_defect: bool
verified_fix_ready: bool = False
def recommend_action(facts: IncidentFacts) -> str:
"""Return a recommended recovery path for an on-call engineer to review."""
if not facts.started_with_new_version:
return "investigate: the new version is not the likely cause"
if facts.verified_fix_ready and not facts.known_good_available:
return "roll forward"
if not facts.known_good_available:
return "roll forward or use safe fallback"
if not facts.compatible_with_current_system:
return "fix compatibility, then roll back; otherwise roll forward"
if facts.old_version_has_same_defect:
return "roll forward or use safe fallback"
return "roll back"
print(recommend_action(IncidentFacts(
started_with_new_version=True,
known_good_available=True,
compatible_with_current_system=True,
old_version_has_same_defect=False,
)))The output of this call is roll back. Note what the function does not do. It does not look at metrics. The trigger rule from the previous chapter answers "is something wrong." This function answers "what is our way out."
Safe fallbacks when neither path is clean
Sometimes no version is safe. Examples are a compatibility break with no quick fix, or a defect shared by every artifact. A safe fallback is a deliberately simple behavior you can switch to while you work. Common choices are:
- A rules-based heuristic that was the system's behavior before ML.
- A conservative default, such as "send to human review" for a fraud or moderation model.
- A cached or last-known-good prediction for a bounded time.
- Disabling the ML feature through a feature flag.
A fallback is not a model rollback, but it belongs in the same decision. It should be prepared and tested before you need it. A fallback invented during an incident is a roll-forward change with all the usual risks.
Time pressure and the cost of each path
Compare the paths by expected time to recovery and by the risk of making things worse.
| Property | Rollback | Roll forward |
|---|---|---|
| Typical time to restore | Minutes if the pointer or revision exists | Hours or longer, since it needs diagnosis, a change, and validation |
| Risk of new defects | Low, because the artifact has run before | Higher, because the change is new |
| Needs root cause first | No | Usually yes |
| Works when state or schema changed | Often not | Yes, if the fix targets the change |
| Leaves the defect in the codebase | Yes, until fixed | No |
Rollback buys time. It does not remove the defect. The bad version still exists in your history, and the change that caused the problem still needs a fix. Treat a successful rollback as the start of the repair, not the end.
Hybrid approaches
The two paths are often combined.
- Roll back, then roll forward. Restore the previous version immediately. Then diagnose, fix, and release a corrected version through the normal canary process. This is the most common sequence.
- Partial rollback. If the new release included several changes, such as a new model plus new preprocessing, revert only the part that failed. This requires that the components are versioned separately. If they ship as one image, you cannot do it.
- Rollback of traffic only. With a canary or blue-green release, shift traffic back to the old environment while leaving the new one running for debugging. The old environment must still be up.
- Roll forward with a flag. If the fix is a configuration change, such as a threshold or a feature toggle, applying it can be as fast as a rollback. Treat it with the same care, since configuration changes can break things too.
# Roll back the serving layer now, keep the broken revision for debugging.
kubectl rollout undo deployment/model-server
kubectl rollout status deployment/model-server
# Record what you did so the later fix has context.
kubectl annotate deployment/model-server \
kubernetes.io/change-cause="rollback from v5 after error-rate trigger" --overwriteCommon errors
- Rolling back without checking compatibility. The pointer moves, the service starts, and predictions are wrong with no errors raised. Check feature schema and consumer expectations first.
- Rolling back for a non-model cause. An upstream data fault affects both versions. You lose time and add a change to the system during an incident.
- Deleting the failed version. You need the artifact and its metadata for the postmortem. Mark it as rejected or archived, and do not remove it.
- Rolling forward under pressure with no canary. A hotfix pushed straight to full traffic can repeat the original failure. Even urgent fixes go through a small-traffic stage when the platform allows it.
- Forgetting the rollback target ages. A version that was fine three months ago may depend on a library, data source, or feature that no longer exists. Keep a short list of rollback candidates and test them regularly.
- Treating rollback as the end. If nobody owns the follow-up fix, the same change returns in the next release.
Exercises
Exercise
Version 7 of a recommendation model raised the error rate right after release. The feature pipeline was changed in the same release and now writes only a renamed set of columns. Version 6 expects the old column names. What do you do, and why?
Show answer
Do not roll the model back alone. Version 6 would fail on missing columns or return wrong predictions. Either restore the old feature output, or revert the pipeline together with the model, if both are versioned and can be reverted as a unit. If neither is quick, roll forward with a fix to version 7, or switch to a safe fallback such as a popularity-based list while you repair it.
Exercise
Error rates rise on both the canary running version 8 and the baseline running version 7 at the same time. Should you roll back version 8?
Show answer
No. Both versions degrade together, so the model version is not the likely cause. Investigate shared dependencies such as the feature pipeline, an upstream data source, or infrastructure. Rolling back would add a change and fix nothing.
Exercise
Name two reasons an engineer might keep the failed model version in the registry after a rollback.
Show answer
The artifact and its metadata are needed for the postmortem and for reproducing the failure, and the team will build a fix from it. Deleting it also removes the audit record of what ran in production. Mark it as rejected or archived instead.