Rolling back and rolling forward
When a release goes wrong, go back to the last good version or ship a fix on top? Why schemas and data decide, and how to keep rollback possible.
Progressive delivery and automated rollbackDeployment strategies: rolling, blue-green and canary
Rolling back and rolling forward
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Rolling back redeploys the last known good version. Rolling forward ships a new version that fixes or reverts the problem. Both aim to restore service fast.
- Rolling back is usually the faster, safer first move, because the old version is already built and was already running in production.
- Rollback breaks when the release changed something the old version can't handle, most often a database schema, a data format or an external contract.
- Expand and contract keeps rollback possible: add new schema alongside the old, and remove the old only in a later release once nothing needs it.
- Decide the rollback plan before you deploy, practise it, and keep the decision simple under pressure: restore service first, investigate second.
Something broke. Now what?
Every team eventually ships a bad release. Progressive delivery catches many of them while only a few users are exposed, but some problems only surface hours later, at full traffic, or in a code path the canary never exercised. At that point there are two ways out:
- Roll back: redeploy the last version that worked.
- Roll forward, also called fix forward: ship a new version that fixes the problem.
Both restore service. They differ in speed, risk and what they assume about the world.
Why rolling back is usually first
A rollback deploys something that was built, tested and already ran in production yesterday. You don’t need to understand the bug to do it. Under pressure, at 3 a.m., with users affected, “go back to what worked” needs the least thinking.
Rolling forward means diagnosing the bug, writing a fix, getting it reviewed and pushing it through the pipeline, all while the outage continues. Sometimes that’s ten minutes. Often it’s an hour, and a hurried fix can be wrong.
So the usual default is: restore service first, investigate second, and rollback is how you restore. How fast rollback is depends on the deployment strategy. Blue-green flips back in seconds. A rolling update takes as long as the original rollout. A feature flag turns off without any deploy.
When rollback doesn’t work
The trouble is that a release doesn’t only change code. It can change things the old code depends on, and those don’t roll back with the binary.
I demonstrated this with SQLite and a small Python app. Version 1 reads a users.name column. Version 2 ships with a migration that splits name into first_name and last_name and drops name, then inserts a new user. Then I rolled the app back to v1:
== migration that drops the old column
v1 reads: [('Ada Lovelace',), ('Grace Hopper',)]
v2 reads: [('Ada', 'Lovelace'), ('Grace', 'Hopper'), ('Lin', 'Wu')]
-- roll back the app to v1:
v1 ERROR: no such column: name
exit=1
The rollback made things worse. v1 can’t start reading users at all. Undoing the migration means re-creating name, and Lin Wu, who signed up while v2 was live, has no name to restore unless someone writes code to rebuild it. Under pressure, this is where teams lose data.
Other things that break rollback the same way:
- Data written in a new format the old version can’t parse, in a database, a queue or a cache.
- A changed external contract, such as a webhook payload partners now depend on.
- One-way operations: emails sent, payments taken, files deleted.
Keeping rollback possible
The fix is to design each release so the previous version can still run against whatever it leaves behind. For schemas the standard pattern is expand and contract: add the new structure alongside the old, have the new version write both, and remove the old structure only in a later release once nothing reads it. I re-ran the demo with only the expand step, and v2 writing both name and the new columns:
== expand only (keep the old column)
v2 reads: [('Ada', 'Lovelace'), ('Grace', 'Hopper'), ('Lin', 'Wu')]
-- roll back the app to v1:
v1 reads: [('Ada Lovelace',), ('Grace Hopper',), ('Lin Wu',)]
exit=0
Rollback works, and Lin Wu is still there. The “contract” step, dropping name, goes out weeks later as its own release, when rolling back past it is no longer a concern. Zero-downtime deploys and schema changes and schema migrations and change management cover this in depth.
When rolling forward is right
Rolling forward is the better choice when:
- Rollback is unsafe, as above.
- The fix is trivial and the pipeline is fast. A typo in a config value, with a ten-minute pipeline, may be quicker to fix than to roll back.
- The problem is behind a flag. Turning off a feature flag is neither a rollback nor a deploy, and is usually the fastest of all.
A common middle path is to revert forward: git revert the bad commit and ship that through the normal pipeline. I tried it on a toy repository where one commit had cut a timeout from 30 seconds to 3:
$ git revert --no-edit HEAD
[main da8eef5] Revert "lower timeout to 3s"
$ git log --oneline
da8eef5 Revert "lower timeout to 3s"
e588f72 lower timeout to 3s
8ead0bd release 1.6.0
$ cat config
TIMEOUT=30
History moves forward, the content matches the last good state, and the fix goes through the same tests and gates as everything else. Reverting a commit covers the Git side, including reverting merges.
Decide before you deploy
The worst time to work out a rollback plan is during the outage. Good habits:
- For each release, know whether it is safe to roll back, and say so in the pull request if it isn’t.
- Practise rollbacks on ordinary days, so the procedure works and people know it.
- Write the decision rule down: if user-facing errors rise after a deploy, roll back first unless the release is marked unsafe.
- Count it. Unplanned fix deployments are what DORA’s deployment rework rate measures, from the metrics lesson.
On-call and incident response picks up from here.
About the video
The embed is a 10½-minute clip from Doug Gorley’s talk “Fix Forward or Roll Back” on the DevOps Live channel (January 2020, 42 minutes in full). Gorley was a cloud architect at xMatters, per the description. By its chapter titles, the clip covers “Fixing forward vs. rollback” and “Incident planning and runbooks”. The earlier chapters on deployment strategies repeat earlier lessons. The description promises the considerations and trade-offs between the two, and how to judge them when microservices depend on each other. It is a small channel and six years old, but the topic hasn’t changed. I had no transcript, so this is from the title, description and chapters. English was judged from the same metadata. Octopus Deploy’s longer 2023 session, which focuses on the database problem, is under deeper.
Where this fits
That finishes delivery and release. The next group goes down a layer, to the machines all this runs on: the Linux server from an operator’s seat.
Check yourself
A release went out 20 minutes ago and checkout errors have tripled. Nothing else changed. Roll back or roll forward?
Roll back, if the release is safe to undo. The previous version is known good and already built, so it restores service fastest. Investigate the bug once users are no longer affected.
The release included a migration that dropped a column the old version reads. What happens if you roll back the app?
The old version fails as soon as it queries the missing column, so the rollback makes the outage worse. You either have to restore the column, which may lose data written since, or roll forward with a fix.
How does git revert relate to rolling forward?
git revert creates a new commit that undoes an earlier one. Deploying it is technically a roll forward, a new version moving through the normal pipeline, whose content matches the old good version for that change.
When is rolling forward the better choice?
When the release can't safely be undone, for example because of an irreversible data change, when the fix is tiny, obvious and quick to ship through a fast pipeline, or when the problem is in a flag that can simply be switched off.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.