Checking how many agents are working

How this works
Contact
← Blog
A heavy steel lever with a curved arrow engraved beside it on a dark bench, an amber light on the return position, and the AMARBARO mark on the plate.
✎blog post

Rollback: the undo button for a website

The short version

A rollback only counts if you have checked the exact path it will take, because the usual way to break it is a change in the data that the old version does not understand.

What this is about

Every software update can go wrong. The best answer is not to never fail. It is to be able to go back, quickly. That is rollback: the undo button for a website. This article explains how it works for a site with a database, what makes it harder than it sounds, and a small change that would have broken ours, which we found before any visitor did.

Why it matters

When an update fails at night, you do not want to think. You want one step that puts the site back as it was. If that step also fails, you are now fixing two things at once. Teams often test the update and never test the way back. The way back is the one you will be using when you are most tired.

How it works

Code goes back easily, data does not

Going back to an older version of the app is easy. We keep the previous image, and a script can start it again. The hard part is the database. When a new version needs a new table or column, it changes the database's shape. The old version then meets a shape it does not know.

A tool called Alembic keeps score of this for our apps. It stores a small note in the database that says which revision the database is at. Each app has its own ordered list of revisions. The old app's list ends at one name. The joined app's list starts at a different one, called 0001, which brings the old shape and the new shape together.

The shortcut we almost took

For the switch of one of our sites, the runbook said to move the note to 0001 with one line. No data changes. That is why it is fast. It is also why it is risky.

After that line, the database says "I am at 0001". The old app, when it starts, looks at its own list and does not find 0001. The runbook's reading was that the old app cannot start, restarts in a loop, and the automatic return to the old version fails. The deploy script would then print ROLLBACK ALSO UNHEALTHY.

No deploy failed to show us this. We found it by reading the runbook before the switch. The runbook said so in one bold sentence, in section 3, and did not show a run of it.

What the rehearsal did show

We rehearsed on a copy of the production dump from 2026-11-12. The dump held 34 tables and 71,217 rows. The restore took 4 seconds. The joined app came up in the same minute, the row counts matched, and the walk over 1,301 addresses passed. The quick rollback took 6 seconds. The full rollback took 5 seconds, with equal counts.

Those numbers are real. They cover the manual path, where a person first sets the note back to the old revision, then runs the return. They do not cover the automatic path, because the automatic path does not set the note back. Our rehearsal passed in the state a manual return needs. It never ran the state the automatic return would meet.

The fix is small

The plan has two parts. First, the stamp goes immediately before the deploy, so the time without a working automatic return is minutes long, not hours. Second, section 6 of the runbook describes the return by hand: set the version back to the old head, then run the rollback command. That step needs a person. Writing it as a manual step makes the dependency visible, which was the point.

What we still do not know

We have not started the old app against a database stamped to 0001. The crash loop is the runbook's reading of how Alembic behaves, not something we watched. A run on a copy would take about a minute and would settle it. If the old app does start, then the automatic return works, and the stamp is only a risk to the manual path. We would rather find out on a copy than in the middle of a switch.

A rollback checklist

  1. Know what changed in the data, not just in the code.
  2. Practice the return on a copy, step by step, with a timer.
  3. Check the automatic return separately from the manual one.
  4. Write the manual steps down. Do not rely on memory at night.
  5. Take a backup first, and copy it off the machine.
  6. After a return, check from outside that the site works.

Why this is worth the effort

Teams often treat rollback as a safety net they hope never to use. We treat it as a feature of the update itself. If going back takes seconds and is written down, you can afford to go forward more often, and with less fear. In our rehearsals the quick return took 6 seconds and the full one 5. Those short times are not luck. They exist because we practiced them on a copy before the real night.

Words you may not know

  • Rollback: returning to the previous working version.
  • Revision: a numbered step in the history of a database's shape.
  • Alembic: the tool our apps use to change the shape of the database.
  • Stamp: moving the revision note without running any change.
  • Runbook: a written list of steps for a task, to follow under pressure.
  • Image tag: the label on a saved version of an app.

Try it

  1. Write a one page runbook for a site you run: the steps to update it and the steps to go back.
  2. Time the "go back" steps once, on a copy.
  3. See our sites at amarbaro.com/web and ask us about your own runbook on gllm.forum.

Comments

No comments yet.

Log in to comment.