Sub topic 3
Compare Deployment Strategies That Support Safe Rollback
Assume you understand model serving, production monitoring, APIs, and basic version control. This chapter focuses on how traffic is moved between model versions. It does not cover the full rollback plan or incident review.
A deployment strategy defines which version receives requests, when traffic moves, and how quickly you can return to the previous version. A rollback is safest when the previous version remains available and traffic can be redirected without rebuilding it.
The main strategies
Blue-green deployment
Blue-green deployment keeps two complete environments:
- Blue runs the current production version.
- Green runs the candidate version.
- A router sends production traffic to one environment at a time.
You deploy and validate the candidate in green. When it is ready, you switch the router to green. To roll back, switch the router back to blue.
This strategy gives a fast rollback and a clear boundary between versions. Its main cost is infrastructure. For a short period, you may need capacity for both environments. You must also consider shared databases, feature stores, caches, and background workers. Switching model traffic does not automatically undo changes made by those systems.
Canary deployment
Canary deployment sends a small percentage of traffic to the new version first. You compare its signals with the stable version, then increase traffic in steps.
A canary limits the number of affected requests when the new model fails. It works well when you can measure outcomes quickly, such as error rate, latency, prediction distribution, or delayed quality labels. Rollback means setting the canary share to zero.
Canaries need careful comparison. The canary and stable versions should receive similar request types. A random sample may miss a failure that affects a particular customer, region, device, or class of input. Use segment-level metrics when risk is uneven.
Rolling deployment
A rolling deployment replaces instances gradually. Some serving instances run the old model while others run the new model during the transition.
Rolling deployment uses less extra capacity than blue-green, but rollback is less immediate. The old artifact may disappear as the replacement continues. Mixed versions can also produce inconsistent predictions, especially when requests share caches or state. Keep enough old capacity available until validation finishes, and make the router identify which version handled each request.
Shadow deployment
A shadow deployment sends copies of production requests to a candidate without using its response for customers. It tests load, latency, and prediction behavior without changing user-visible decisions.
Shadowing is useful before a canary, but it is not a complete rollback strategy. The candidate does not experience the same response-time pressure or downstream effects as an active model. A candidate that looks safe in shadow mode still needs controlled production traffic.
Compare the trade-offs
| Strategy | Rollback speed | Extra capacity | Main risk |
|---|---|---|---|
| Blue-green | Very fast | High | Shared state is not reversible |
| Canary | Fast | Medium | Metrics or traffic sample are misleading |
| Rolling | Medium | Low | Mixed versions and lost old capacity |
| Shadow | Not applicable to active traffic | Medium | Results do not prove serving safety |
For high-risk models, combine strategies. Use shadow traffic for load checks, then a canary for real behavior, while retaining a blue-green-style stable environment for immediate fallback.
Choose traffic controls deliberately
Traffic controls should make the rollback action small and observable. A typical canary might use 10% traffic for ten minutes, followed by 50%, then 100%. Each step needs exit criteria for errors, latency, model quality, and business impact.
def next_traffic_step(
current_percent,
error_rate,
baseline_error_rate,
p95_latency_ms,
max_latency_ms,
):
if error_rate > baseline_error_rate * 2:
return "rollback", 0
if p95_latency_ms > max_latency_ms:
return "rollback", 0
steps = [10, 50, 100]
for step in steps:
if step > current_percent:
return "advance", step
return "hold", current_percent
action, traffic = next_traffic_step(
current_percent=10,
error_rate=0.025,
baseline_error_rate=0.01,
p95_latency_ms=180,
max_latency_ms=250,
)
print(action, traffic)Exercise
Exercise
Which strategy gives the fastest traffic rollback, and what dependency can still make that rollback incomplete?
Show answer
Blue-green usually gives the fastest switch because the old environment remains available. Shared state, such as database changes, feature-store writes, or cache contents, can still make the rollback incomplete.