Sub topic 7
Checking that the old version still fits the system
This chapter assumes you can read Python and use a model registry alias, as covered in the earlier chapters of this tutorial. It also assumes you know what a feature pipeline is and what a canary release does.
A rollback restores an old model artifact. It does not restore the system around that artifact. While version 4 was live, the team may have changed the feature pipeline, the preprocessing code, the response format, or the library versions on the servers. Version 3 was a known good model when it shipped. That says nothing about whether it works with the system as it is today.
The goal of this chapter is a short, repeatable check you can run before you move the pointer. A rollback that fails for compatibility reasons turns one incident into two.
What "fit" means
A model version sits between three things: its inputs, its runtime, and its consumers. Each can drift after the model was released.
| Surface | What can change while the new version is live | How the old version breaks |
|---|---|---|
| Input features | A column is renamed, dropped, retyped, or rescaled. A new feature replaces an old one. | The server raises a missing-column error, or it silently feeds wrong values and returns bad predictions. |
| Preprocessing | The tokenizer, encoder, imputer, or scaler is updated and shared by all versions. | The old model sees inputs in a form it was never trained on (training-serving skew). |
| Runtime dependencies | The serving image upgrades scikit-learn, PyTorch, or the model-loading library. | The old artifact fails to load, or loads and behaves differently. |
| Output contract | Consumers start reading a new field, a new score range, or a new label set. | Downstream code crashes or misreads results. |
| Operating parameters | Decision thresholds and calibration are tuned for the new model's score distribution. | The old model's scores cross the same threshold at a very different rate. |
The first three are about whether the old model can run. The last two are about whether its answers still mean what the rest of the system assumes.
Inputs: schema and meaning
The first check is mechanical. For every feature the old version reads, the live feature source must still provide a column with the same name and type.
Matching names and types is necessary, not sufficient. A feature can keep its name and type while its meaning changes. Examples are account_age_days switching from days to hours, a currency amount moving from dollars to cents, or a null-fill value changing from 0 to -1. These changes pass a schema check and still corrupt predictions.
To catch them, compare the live distribution of each input with the distribution the old version was trained on. Most registries let you store training statistics as version metadata, and this check is one reason to record them. A feature whose live mean or range has moved far from the old training statistics deserves a look before you roll back.
A related case is a feature that the old model needs but that is no longer computed. If the pipeline stopped writing it, rollback cannot work until someone restores it or backfills it. This is the most common hard blocker.
Preprocessing: the hidden half of the model
Many failures happen because the preprocessing code is not part of the artifact. If the model expects standardized numbers or a particular category encoding and the pipeline now produces something else, the model still runs and returns confident wrong answers. Nothing raises an error.
There are two ways to avoid this:
- Package preprocessing with the model, for example as a scikit-learn
Pipelineor a saved transformer graph, so that one version number covers both. - If preprocessing is shared code, record which preprocessing version each model version needs, and have the serving layer check it.
Encoders deserve special attention. A label encoder or vocabulary fitted for version 4 assigns different integer IDs than the one fitted for version 3. Embedding tables and vocabularies tied to a specific model have the same issue. Keep these artifacts versioned alongside the model, never overwritten in place.
Runtime dependencies
An artifact is loaded by a specific stack: Python version, framework, and often a serialization format. Pickle-based formats are the most fragile, because a different library version can fail to unpickle or can change behavior.
Which rollback path you use decides how much this matters:
- If the model version is baked into the container image, as in the
kubectl rollout undoapproach, the old image carries its own dependencies. This is the safest case, because the old environment comes back with the model. - If the serving image is shared and loads artifacts by alias, the old artifact must run on the current image. Test this explicitly. Record the framework version used at training time as registry metadata, and compare it with the running image.
Consumers and the output contract
Consumers are the systems that call your service or read its output: an application, a batch job, a dashboard, another model. While the new version was live, they may have started to depend on its behavior.
Check these points:
- Fields. Does the old version return every field consumers read now, with the same types? A new version that added
reason_codesmay have led the caller to require it. - Score semantics. Does the score keep the same range, and is it calibrated the same way? A change from a raw margin to a probability breaks any threshold downstream.
- Label sets. If version 4 added a class, the consumers may handle it. The old version never emits it, which is usually safe. The reverse is dangerous.
- Chained models. If another model uses this model's output as an input feature, rolling back changes that downstream model's inputs. It may need to roll back too, or at least be evaluated.
Thresholds and business rules are part of the contract. If you raised the fraud-block threshold from 0.5 to 0.8 when you shipped version 4, version 3 with a threshold of 0.8 may block almost nothing. The threshold should move with the model version, ideally stored in the same registry entry or config revision.
Automating the compatibility check
A pre-rollback check is cheap to write when the registry stores a contract with each version. The script below compares a candidate version's recorded contract with the live system. It uses plain dictionaries so you can adapt it to MLflow tags, a model signature, or a JSON file in your artifact store.
def check_rollback_candidate(candidate, live_features,
supported_preprocessing, consumer_fields):
"""Return a list of reasons the candidate cannot safely serve now."""
problems = []
# Inputs: names and types must still be produced live.
for name, dtype in candidate["inputs"].items():
if name not in live_features:
problems.append(f"input '{name}' is no longer produced")
elif live_features[name] != dtype:
problems.append(
f"input '{name}' is {live_features[name]} live "
f"but the model expects {dtype}"
)
# Preprocessing: the serving layer must still support the needed version.
if candidate["preprocessing"] not in supported_preprocessing:
problems.append(
f"preprocessing '{candidate['preprocessing']}' is not supported"
)
# Outputs: every field consumers read must still be returned.
for name, dtype in consumer_fields.items():
if name not in candidate["outputs"]:
problems.append(f"output '{name}' is missing")
elif candidate["outputs"][name] != dtype:
problems.append(f"output '{name}' has the wrong type")
return problems
candidate_v3 = {
"version": "3",
"inputs": {
"amount": "float",
"merchant_category": "str",
"account_age_days": "int",
"region": "str",
},
"preprocessing": "prep-2",
"outputs": {"score": "float"},
}
live_features = {
"amount": "float",
"merchant_category": "str",
"account_age_days": "float",
"device_risk": "float",
}
problems = check_rollback_candidate(
candidate_v3,
live_features,
supported_preprocessing={"prep-3"},
consumer_fields={"score": "float", "reason_codes": "list"},
)
if problems:
print(f"Rollback to version {candidate_v3['version']} blocked:")
for problem in problems:
print(f"- {problem}")
else:
print("Compatible: safe to move the alias.")Running it prints:
Rollback to version 3 blocked:
- input 'account_age_days' is float live but the model expects int
- input 'region' is no longer produced
- preprocessing 'prep-2' is not supported
- output 'reason_codes' is missingThe check covers structure only. It cannot catch a change in meaning, such as hours replacing days, so it complements the statistical comparison described earlier and does not replace it.
Testing behavior before the switch
Structural checks say the old version can run. A behavioral check says it still answers sensibly. Two methods work well:
- Replay. Send a sample of recent live requests, with their current features, to the old version in a staging or shadow deployment. Compare score distributions, error rates, and latency with what the live version produces. Large unexplained gaps mean the system has drifted away from the old model.
- Golden examples. Keep a small set of inputs with known acceptable outputs for each version, and run them against the candidate. This is fast enough to run in the middle of an incident.
If your release strategy already keeps the previous version running, as in a blue-green setup, you can run these checks against real traffic at almost no extra cost. This is one reason blue-green rollback is cheap.
When the check fails
A failed check does not always mean abandoning the rollback. It tells you what the options are:
- Restore the missing piece. Re-enable a dropped feature, or deploy the old preprocessing version next to the new one. This is quick when the change was recent and isolated.
- Roll back more than the model. Revert the pipeline or preprocessing change with it, if the two were released together.
- Use an older, compatible version. Version 2 may fit when version 3 does not. Check that it is still acceptable on quality.
- Roll forward. Fix the new version instead. The next chapter covers this decision.
- Fall back to a safe default. Serve a rules-based or cached response while you repair the system.
That last point is the main operational lesson. A rollback target decays as the system changes around it. A target that was valid at release can be invalid a month later, and a scheduled check tells you before you need it.
Exercise
Your team ships version 5 of a pricing model. Version 5 needs a new feature, competitor_price, and the pipeline team removes the unused list_price_old column the same week. Version 4 reads list_price_old. Version 5 starts returning bad prices, and you consider rolling back to version 4. Which check blocks the rollback, and name two ways to proceed?
Show answer
The input check blocks it, because version 4 needs list_price_old, which the pipeline no longer produces. You can restore or backfill list_price_old and then roll back, or roll back the pipeline change together with the model. Rolling forward with a fix to version 5 is also valid, as is serving a safe default price while you repair the system.
Exercise
A model's score threshold was raised from 0.5 to 0.8 when version 4 shipped. Version 4 is rolled back to version 3 by moving the registry alias, and the threshold stays at 0.8 in a separate config file. What can go wrong, and how do you prevent it?
Show answer
Version 3 was tuned for a threshold near 0.5, so a threshold of 0.8 may flag far fewer cases than intended and cause missed detections without any error. Prevent it by storing the threshold with the model version, in registry metadata or a versioned config, and changing both in one step when the pointer moves.
Exercise
Why can a schema check pass while the rolled-back model still produces wrong predictions? Give one example and one way to detect it.
Show answer
A schema check compares only names and types. A feature can keep both while its meaning changes, for example account_age_days switching from days to hours. Detect it by comparing live feature distributions with the training statistics stored for the old version, or by replaying recent requests through the old version and comparing its outputs with expectations.