Contents Lesson 9 of 16

8 min read · professional

Deploy so that rolling back is boring

By the end of this lesson you will have a health answer that names the commit it was built from, a RUNBOOK.md with the steps to roll back on your host, and three times written beside them: deploy, roll back, roll forward.

Deploying is easy. The property worth designing for is the other direction: can you undo it in a minute, without thinking?

One command, from a branch, every time

Push to a branch, CI runs, the build deploys. No manual steps, no "I also copied that file", no step that exists only in your memory.

The reason is not elegance. A deploy with a manual step is a deploy you cannot reproduce, which means an outage at an inconvenient moment turns into archaeology. Everything about production discipline is about removing decisions from moments when you are least able to make them.

Rollback is the feature

Ask one question of your setup: if this release is bad, how do I get back to the previous one, and how long does it take?

If the answer involves reverting a commit and waiting for a full build, that is minutes of a broken tool. If it is selecting the previous deployment, it is seconds. Most hosts give you the second for free and most people never check which they have — so check it now, while nothing is wrong.

Then do it once on purpose. A rollback you have performed is a rollback you will perform calmly.

The database is the part that does not roll back

Code goes backwards easily. A migration that dropped a column does not.

So: migrations are additive, deployed before the code that needs them, and destructive changes wait until the new code has been running a while. Add the column, ship code that writes both, ship code that reads the new one, and only then remove the old — the same shape as the persistence migration in Build a Dashboard, for the same reason.

A schema change and a code change in one deploy is the thing that makes a rollback impossible exactly when you need it.

Environments, honestly

For a personal tool, production and your laptop is a reasonable answer, and pretending otherwise adds ceremony without safety.

What matters is that the deployed thing is built from a committed state, not from whatever your working tree happened to contain. If you cannot say which commit is live, you cannot reason about a bug report — and for a personal tool the bug report comes from you, confused, six weeks later.

Try it now

Deploy, then roll back to the previous version, then roll forward. Time all three. Those three numbers tell you what an incident will actually cost you, and most people discover the answer during the incident instead.

The prompt

Mock mode on, plan mode on, and paste:

Add a commit field to the health answer: the commit the running build
came from, read from VERCEL_GIT_COMMIT_SHA on Vercel (or my host's
equivalent), cut to seven characters, and "local" when it is not set.
Then write RUNBOOK.md with one section, Rollback: how a deploy happens,
how to return to the previous deployment on this host, how to go
forward again, and how to tell from the health answer which commit is
live. Take the host's steps from its documentation and say which page.
Do not deploy, roll back or change any setting yourself. Leave a Times
line empty for me. Done means npm test, npm run typecheck,
npm run lint and npm run check:leak green; show me the diff.

A good answer changes the health route and its test, adds RUNBOOK.md, and touches nothing on the host: rolling back is something you rehearse, not something an agent does for you.

Check it yourself

These checks need the change live, so commit it and deploy it first, the way your host deploys (for most hosts, a push to main):

npm test && npm run typecheck
git status          # the files you expect, and no .env file
git add -A
git commit -m "Health names the live commit; RUNBOOK.md says how to roll back"
  1. After the deploy, curl -s https://your-tool.example/api/health shows the same commit as git rev-parse --short=7 HEAD. If it says local, the host is not passing the commit to the build: on Vercel, turn on "Automatically expose System Environment Variables" in the project's settings and deploy again.
  2. Roll back on the host and read the health answer until it names the previous commit. Write down how long that took.
  3. Roll forward and time it the same way. Then push a small change and see it go live: on some hosts a rollback pauses automatic promotion until you undo it, and you want to find that out now.
  4. RUNBOOK.md holds the three times and today's date, and someone else could follow its steps without asking you.
Compare with ours
// in the health route
commit: (process.env.VERCEL_GIT_COMMIT_SHA ?? "local").slice(0, 7),
RUNBOOK.md
Rollback (Vercel)
  Deploy      push to main; production builds from that commit
  Back        Deployments, the previous production deployment, Instant Rollback
  Forward     promote the newer deployment again; then check the next push goes live
  Which       curl the health URL and compare "commit" with git log
  Times       <date>   deploy <m:ss>   back <m:ss>   forward <m:ss>

The full state at the end of this unit is on the starter's branch ref/ship-your-tool/u3.

Checkpoint

git status          # RUNBOOK.md, now holding your three times, and no .env file
git add -A
git commit -m "RUNBOOK.md: rollback rehearsed and timed"

Then answer this lesson's questions.