Rollback: noticing a bad release and undoing it
A bad release is a clock
Section titled “A bad release is a clock”Every strategy in this module can go back, and none of them does it instantly. From the moment a bad version first serves a request until the old one serves everything again, users are being hurt, and that time is the sum of three parts.
- Time to detect. From the first request to the new version until the alert fires. The alert needs enough requests to trust a rate, and it needs the bad share to reach its threshold.
- Time for a person to act. For all but the canary, nothing happens until someone decides to roll back. A person reacts after sets this: 180 s by default.
- Time for the strategy to go back. A routing change takes about a second. Starting the old version again takes as long as a start.
In Kubernetes the last part is a command. kubectl rollout undo rolls a Deployment back to the previous revision, or to a revision you name with --to-revision. The documentation notes that each rollback updates the revision of the Deployment, so going back is a new rollout toward an old template. It is also why a rolling deployment goes back at the speed it went forward.
Mental model. Exposure is detection, plus waiting for a decision, plus the mechanism. Shortening any one helps, and the lab shows that they are not equally large.
Try it: where the time goes
Section titled “Try it: where the time goes”Open the lab as it is, with its bad release, and look at the table of the four strategies.
A fleet of identical instances serves the traffic. A new version, worse than the old one, has to replace it. Choose how: all at once, rolling, blue/green or canary. All four run on the same traffic, with the same alert, so the table shows what each costs in users hit, in time to notice, in time to undo, in capacity and in money.
- Old version (v1), serving
- Old version (v1), kept idle
- New version (v2), serving
- Starting, not serving yet
At 0:52: 1 instances serve the new version, 10 the old one and 0 are starting. 5% of the traffic goes to the new version. The fleet can serve 1,100 requests a second, and 623 arrived this second. The alert has fired.
The deployment run
- Users hit by the release
- 0.008%expected share with a bad request caused by the release
- Time to detect
- 2 sfrom the first request to the new version to the alert
- Time to roll back
- 2 sfrom the alert; a canary rolls back by itself
- Lowest serving capacity
- 100%Busythen the traffic is 60% of what is left
- Requests refused
- 00% of all requests, for lack of capacity
- Extra instances at the peak
- 10.9 extra instance-minutes in all
- Rollout length
- Rolled backuntil the new version has all the traffic
Canary: the alert fired at 0:52, 2 s after the first request reached the new version. The old version served everything again at 0:54, 2 s after the alert. From the first request to the new version until the old version served again took 4 s, and 0.008% of the users were hit.
Traffic on the new version, and capacity
- Traffic on the new version
- Serving capacity
Users hit so far
- Users hit
Instances paid for
- Instances paid for
- Fleet size
Drag on a chart, or use the moment slider, to move through the run.
| Strategy | Result | Users hit | Time to detect | Time to roll back | Lowest capacity | Refused | Extra instances · minutes |
|---|---|---|---|---|---|---|---|
| All at once | Rolled back | 7.4% | <1 s | 3.9 min | 0% | 59,638 | 0 · 0 |
| Rolling | Rolled back | 11.4% | 50 s | 7.2 min | 80% | 0 | 0 · 0 |
| Blue/green | Rolled back | 7.4% | <1 s | 3 min | 100% | 0 | 10 · 38.7 |
| Canary · shown above | Rolled back | 0.008% | 2 s | 2 s | 100% | 0 | 1 · 0.9 |
Each row is one run of 14 minutes of simulated time, on the same traffic sample. Choose another sample to see how much a single run can differ.
How long a canary needs to be sure
A release that is bad for 8.5% of requests, against 0.5% for the old version, takes about 20 requests to tell apart, with a 5% risk of a false alarm and an 80% chance of seeing the regression. The alert in this lab fires once 100 requests have been seen; the table counts the 100 requests that a careful judgement needs.
| Canary share | 60 req/s in all | 600 req/s in all | 6,000 req/s in all |
|---|---|---|---|
| 1% | 2.8 min | 17 s | 2 s |
| 5% | 33 s | 3 s | <1 s |
| 10% | 17 s | 2 s | <1 s |
| 25% | 7 s | <1 s | <1 s |
| 50% | 3 s | <1 s | <1 s |
A simple model: independent requests, a known normal rate, one fixed rate for the new version. It gives an order of magnitude. A smaller regression, or a noisier measure, needs many more requests.
The run as text and as a table
What happened with Canary
- At 0:00, the rollout starts.
- At 0:50, the canary reaches step 1: 5% of the traffic.
- At 0:50, the first request reaches the new version.
- At 0:52, the alert fires.
- At 0:53, the rollback starts.
- At 0:54, the old version serves all the traffic again.
| Elapsed | Old (v1) | New (v2) | Starting | Traffic to v2 | Capacity (req/s) | Refused | Failed so far |
|---|---|---|---|---|---|---|---|
| 0:00 | 10 | 0 | 1 | 0% | 1,000 | 0 | 3 |
| 1:10 | 10 | 0 | 0 | 0% | 1,000 | 0 | 205 |
| 2:20 | 10 | 0 | 0 | 0% | 1,000 | 0 | 408 |
| 3:30 | 10 | 0 | 0 | 0% | 1,000 | 0 | 626 |
| 4:40 | 10 | 0 | 0 | 0% | 1,000 | 0 | 849 |
| 5:50 | 10 | 0 | 0 | 0% | 1,000 | 0 | 1,057 |
| 7:00 | 10 | 0 | 0 | 0% | 1,000 | 0 | 1,252 |
| 8:09 | 10 | 0 | 0 | 0% | 1,000 | 0 | 1,471 |
| 9:19 | 10 | 0 | 0 | 0% | 1,000 | 0 | 1,681 |
| 10:29 | 10 | 0 | 0 | 0% | 1,000 | 0 | 1,874 |
| 11:39 | 10 | 0 | 0 | 0% | 1,000 | 0 | 2,091 |
| 12:49 | 10 | 0 | 0 | 0% | 1,000 | 0 | 2,303 |
| 13:59 | 10 | 0 | 0 | 0% | 1,000 | 0 | 2,501 |
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random at a steady average rate: each second brings a random number of them (a Poisson count). All four strategies get the identical arrivals, and the identical random numbers for routing and for failures, so a difference between two rows comes from the strategy and not from the luck of the draw. Choose another traffic sample to see how much one draw can differ from another.
- Every instance serves up to 100 requests a second (2 at a time, 20 ms each). Requests beyond what the instances that are ready can serve are refused. An instance serves nothing while it starts and while its readiness check is passing, and it is paid for all that time.
- A request is bad when it fails or takes longer than the latency objective. With the old version, 0.5% of requests are bad. The new version adds the share of failures and of slow requests that you set. Each request is bad or not independently of every other.
- The alert counts the requests since the routing last changed, and fires when at least 100 have been seen and the share of bad ones reaches the threshold. A canary watches only the requests that reach the new version. The other strategies watch the whole service, as an alert on the service’s error rate does, so a bad version that serves a small share of the traffic is diluted. Requests refused for lack of capacity are not counted by the alert.
- Only the canary rolls back by itself. For the other strategies a person acts after the time you set. A rollback that is only a change of routing (blue/green before the old fleet is removed, a canary before its last step) takes about two seconds: the alert is checked every second, and the change then takes a second to reach every request. Any other rollback starts the old version again, a batch at a time for a rolling deployment and all at once for the others, and takes as long as a start.
- A user’s visit is 5 requests, all to the same version. The share of users hit is the expected share of visits, over the whole run, that go to the new version and have at least one request that is bad because of the release. It is an expected value from the model, not a count. Users are not followed from one visit to the next.
Simplifications
- A canary step ends when its minimum time has passed and the new version has served 100 requests during the step; the instances for the next step are assumed to be started by then. A canary’s share is a routing weight, and the capacity of the old and the new instances is pooled.
- The table of times to be sure uses the sample size of a one-sided test of a proportion, with a 5% risk of a false alarm and an 80% chance of seeing a real regression, by the normal approximation. It assumes independent requests, a known normal rate and a regression that is the same for every request. It gives the order of magnitude, not a promise: real regressions depend on the request, the user and the time of day, and a rate of one in a thousand needs far more requests than a rate of one in ten.
- The alert looks at one measure, the share of bad requests, against a fixed threshold. Real canary analysis compares several measures (latency percentiles, saturation, business figures) and often compares the canary with a control group of instances of the same age rather than with a fixed rate. Checking again every second against a fixed threshold also raises the chance of a false alarm, which the run shows when the release is good.
- Databases, caches that need to warm up, long connections and sessions that move from one version to another are not modelled. A rollback is assumed to be safe, which it is not when the new version has changed data in a way the old one cannot read: that is why schema changes are done separately, in steps (expand and contract).
- Feature flags are not modelled here. A flag turns code that is already deployed on for a share of users and can turn it off in seconds without moving any instance: the same arithmetic as a canary, with a rollback that costs no start-up time.
- A container image pull, a readiness probe and the load balancer’s connection draining are reduced to one start time and one readiness time. Autoscaling during the rollout is not modelled.
Parameter values are illustrative. They are not benchmarks of any real product.
For All at once, Time to roll back is 3.9 min. It is 180 + 1 + 50, which is 231 s: the 180 s of A person reacts after, a second for the decision to take effect, and the 50 s that starting the old fleet takes. For Blue/green it is 3 min, since going back is a routing change of about 2 s and the rest is the person. For Canary it is 2 s: nobody has to decide, because a canary rolls back by itself.
Rolling is the slowest, with Time to detect of 50 s and Time to roll back of 7.2 min, and Users hit by the release is 11.4%. Two things explain it. Its alert watches the whole service, as a dashboard of the service’s error rate does, and while the new version serves only a small share of the traffic the bad requests are diluted among the good ones, so the alert takes longer to reach its threshold. And going back is a rolling deployment toward the old version, a batch at a time, with 50 s for each.
Now set A person reacts after to 60 s. Users hit by the release becomes 2.9% for all at once and for blue/green, 7.1% for rolling, and the canary stays near 0.01%. Set it to “at once”: rolling is 4.2%. The person’s delay moved the result more than the choice between all at once and blue/green did, and the canary was independent of it. Put it back to 180 s.
At “at once”, all at once shows a smaller share of users hit than blue/green does (0.061% against 0.12%). It stops the new version sooner because going back means shutting the new version down; the cost appears in Requests refused, 59,765 for all at once and 0 for blue/green, and that is the point of the table having more than one column.
Rolling forward, and when going back is unsafe
Section titled “Rolling forward, and when going back is unsafe”Going back assumes that the old version still works with what the new one did. Fowler’s blue/green page says it plainly: a change to the database complicates the switch. If the new version wrote rows in a format the old version cannot read, or dropped a column that the old version needs, then pointing the traffic back at the old fleet brings back a version that now fails. The lab assumes a rollback is safe, which it is not in that case.
Two answers are used. One is to make the change in steps so that the old version keeps working, which is the last lesson of this module. The other is to roll forward: leave the release in place and ship a fix as another release. It takes the same time as any deployment and may leave the users exposed for longer, and it is sometimes the only choice, as when a rollback would put old code on top of new data.
What the threshold trades
Section titled “What the threshold trades”The alert is a threshold. Set Alert at (bad requests) too low and the alert fires for a release that is fine. Set it too high and it does not fire for one that is bad. The Site Reliability Workbook puts it this way: if the acceptance criteria are too strict there are many false positives, and if they are too loose a bad deployment is more likely to go unnoticed.
Try both. Set Extra failures to 0% so that the release is as good as the old one, and Alert at (bad requests) to 1%. All at once and blue/green roll out with no alert, and Rolling and Canary both show “False alarm, rolled back”: a chance run of bad requests in a small sample crossed a low threshold, and the release was undone. For the canary the alert fired 5 min after its first request. A good release cost a rollback.
Now put Alert at (bad requests) back at 3% and set Extra failures to 1%. The release is bad for 1.5% of requests, three times the normal 0.5%, and the alert never fires. Every row of the table reads “Bad release not caught”. Users hit by the release is 4.7% for all at once, 4.4% for rolling, 4.7% for blue/green and 2.5% for the canary, and those figures would keep growing. The canary reached fewer users only because its rollout is slow; it did not find the problem. A canary or any other strategy gives a bad release a smaller audience only if the alert can see the problem.
What the alert should measure, and why a symptom such as the share of failed requests is a better thing to alert on than a cause, is the subject of the alerting on symptoms lesson, and error budgets say how much of a bad release a service can afford.
What happens if the person is faster than the alert
Section titled “What happens if the person is faster than the alert”A quicker human cannot help if the alert is slow, and a quick alert cannot help if the person is slow. Look at what each strategy depends on in the default run. The canary depends on the alert alone. Blue/green and all at once depend on the alert and then on the person, and rolling on both and on its own slow way back. A team that cannot make a person act in seconds gets most from a mechanism that does not need one, which is what a canary with automatic rollback is. A team that has no automatic rollback gets most from a short reaction time, and from keeping the old fleet long enough to be able to switch back.
Check your understanding
Section titled “Check your understanding”Check your understanding: rollback and detection
This quiz needs JavaScript to check your answers.
- A bad release’s exposure is the time to detect, plus the time for a person to act, plus the time the strategy needs to go back.
- In the default run all at once goes back in 3.9 min (
180 + 1 + 50s), blue/green in 3 min, rolling in 7.2 min and the canary in 2 s, with 7.4%, 7.4%, 11.4% and 0.008% of users hit. - With a person who reacts in 60 s, all at once and blue/green hit 2.9% of users; the person’s delay mattered more than the choice between them.
- A threshold of 1% on a good release gives false alarms for rolling and the canary. A real failure of 1.5% against a 3% threshold is not caught by any strategy.
- Going back is not safe when the new version changed data in a way the old one cannot read. The alternatives are changing data in steps, and rolling forward with a fix.
Next: feature flags, which separate deploying code from releasing it.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.