TL;DR
|
A deployment rollback is the process of undoing a release by returning an app to its previous working version. When a new release causes errors, slows the site down, or breaks a feature, rolling back gets users back to something that works while the team investigates.
It sounds simple, and for code it often is. The complications come from data, and from changes that can't easily be undone. This guide explains the ways to roll back, how to handle the database, and when fixing forward is the better choice.
Key takeaway: a rollback has two parts, the code and the data. Code is easy to restore. Data usually isn't.
Code lives in version control, so every previous version still exists. Putting an older version back is mostly a matter of deploying it again.
Data is different. Between the release and the rollback, users may have signed up, placed orders, or edited content. If the release also changed how data is stored, the old code may not understand the new data, and putting the old data back would erase everything users did in between.
So rollbacks usually restore the code and leave the data alone, and the hard cases are releases that changed the database.
Key takeaway: the right method depends on how fast you need to act and whether the release changed data.
| Method | How it works | Speed | Undoes data changes? |
|---|---|---|---|
| Redeploy the previous version | Deploy the last working version again | Minutes | No |
| Revert in Git | Create a new commit that undoes the bad change, then deploy it | Minutes | No |
| Switch traffic back | With blue-green deployments, send traffic back to the old copy that's still running | Seconds | No |
| Turn off a feature flag | Disable the new feature without deploying | Seconds | No |
| Restore a backup | Return code and data to the moment the backup was taken | Minutes to hours | Yes, and it erases everything since |
Reverting in Git keeps a clear record of what happened, because the undo is a commit of its own. Restoring a backup is the most complete option and the most drastic, because data created after the backup is lost.
Key takeaway: if the problem is small and the fix is obvious, shipping a fix can be safer than undoing the whole release.
Fixing forward, also called rolling forward, means releasing a new version that fixes the problem instead of returning to the old one. It avoids the data complications of a rollback, and it suits small, well-understood bugs.
Roll back when the problem is serious, the cause is unclear, or a fix would take more than a few minutes to write and test. Fix forward when the cause is obvious, the fix is small, and rolling back would cause its own trouble, for example because the release changed the database.
Key takeaway: plan database changes so the previous version of the code can still run against them.
A database migration that adds a column is easy to live with: the old code simply ignores it. A migration that renames or removes a column is not, because the old code expects it to be there.
Two habits make rollbacks safer:
Key takeaway: many rollback problems come from not planning the rollback before the release.
| Mistake | What happens | How to avoid it |
|---|---|---|
| No rollback plan | The team works out how to undo a release in the middle of an incident | Decide how each release would be rolled back before it ships |
| Restoring a backup by reflex | Every order, sign-up, or edit since the backup is lost | Restore code first, and only restore data when you must |
| Rolling back code but not configuration | The old code runs with new settings and fails differently | Keep configuration in version control alongside the code |
| A migration the old code can't handle | The rollback itself breaks the site | Make database changes the previous version can live with |
| Testing only the happy path | Problems appear only with real data and real traffic | Test releases against a realistic copy of production first |
Key takeaway: on Upsun Cloud, you roll back code through Git, and you can restore an environment's code and data from a backup.
Upsun Cloud deploys whatever is in your Git repository, so the usual way to roll back code is to revert the change in Git and push. That creates a new commit that undoes the bad one, and Upsun Cloud builds and deploys it like any other change.
If a bad push is still building or deploying, you can stop it with upsun activity:cancel, as described in the docs on cancelling an activity.
For changes that affect data, backups give you a fuller rollback:
| What to know | Details from the Upsun docs |
|---|---|
| What a backup includes | The environment's complete code and data, including every service's data and files stored on mounts |
| Automatic backups | Production environments are backed up automatically on a schedule |
| Manual backups | Admins can take one before a risky change with upsun backup:create |
| Restoring | upsun backup:restore <BACKUP_ID> returns the environment's code and data to the moment of the backup. The resources of each container also return to what they were then |
| Your Git repository | Isn't changed by a restore. To keep the restored code, revert it in Git yourself. To go back to your latest code, redeploy or push a new change |
| Downloading | Backups are stored on Upsun Cloud and can't be downloaded. Export your data separately if you need a copy |
The docs suggest taking a backup before merging another environment into production. Testing the change in a preview environment first, which by default starts with a copy of its parent's data, also catches many problems before a rollback is needed. Our guide What is a preview environment? explains how.
You can deploy on Upsun Cloud free for 15 days, with no card needed, or read the docs on restoring an environment.
Returning an app to its previous working version after a release causes problems.
A rollback returns to the previous version. A roll forward, or fix forward, releases a new version that fixes the problem instead.
Sometimes. Some migrations include an undo step, but data written since the release can make it unsafe. Restoring a backup also undoes data changes, but loses everything created since the backup.
Use git revert to create a new commit that undoes the bad change, then deploy that commit. This keeps the full history, unlike rewriting it.
As short as possible. Redeploying or reverting code usually takes minutes, switching traffic back in a blue-green setup takes seconds, and restoring a large backup can take longer.
Upsun Cloud rolls back code through Git: revert the change and push. For code and data together, restore the environment from a backup.