Writing

Making changes you can take back: safe releases for infrastructure

/8 min read/Reliability/#sre/#change-management/#releases/#canary/#ansible

A large share of incidents start with something someone changed: a deploy, a config push, a package upgrade, a firewall rule. That is not a reason to stop changing things. It is a reason to make each change easy to check, easy to watch and easy to undo.

This post covers the habits that make that true. None of them are new. The hard part is doing them every time, including for the “tiny” change on a Friday afternoon.

1. Why changes cause incidents

A running system is in a state that works, more or less. A change moves it to a new state that nobody has run in production yet. Testing reduces the risk, but test environments differ from production in traffic, data, scale and the odd host that was hand-patched two years ago.

So the goal is not “never break anything”. It is:

  • Find out quickly when a change is bad.
  • Limit how much it can break before you find out.
  • Get back to the last good state fast.

Everything below serves one of those three.

2. Make every change reversible

Before you make a change, know how you will undo it. Write it down in the change itself, not in your head.

Some changes reverse cleanly: redeploy the previous build, revert the commit, flip a flag back. Others do not:

  • Database schema changes that drop or rewrite data.
  • Data migrations that transform records in place.
  • Deleting resources, volumes or DNS records.
  • Changes that other systems react to, such as rotating a credential.

For those, split the change so the risky part is reversible for as long as possible. Add the new column before removing the old one. Write to both formats before reading from the new one. Keep the old resource around, unused, until you are sure. The expand-then-contract pattern costs an extra step and saves you from a one-way door.

If a change truly cannot be undone, treat it differently: more review, a tested backup, a smaller first step and someone else watching.

3. Small batches

A change that bundles ten things is hard to review, hard to test and hard to debug. When it goes wrong, you do not know which of the ten did it, and rolling back undoes the nine good ones too.

Smaller changes help in a few ways:

  • Review is real, because a reviewer can actually read the diff.
  • When something breaks, the suspect list is short.
  • Rollback is cheap, so people are willing to do it early.

Shipping small and often also keeps the release process exercised. A pipeline that runs ten times a day is a pipeline you trust. One that runs once a quarter tends to have surprises.

4. Pre-change checks

Before anything touches production, check what you can cheaply:

  • The diff. Read what will actually change, not what you meant to change.
  • A dry run. Many tools can show the effect without applying it: a plan from your infrastructure-as-code tool, a diff from your config tool, a server-side dry run against the cluster API.
  • Health of the target. Do not start a change on a system that is already alerting. You will not be able to tell your problem from the existing one.
  • Dependencies. Is anyone else changing something related right now?
  • The rollback path. Is the previous version still available? Does the rollback step actually work?

For configuration managed with Ansible, check mode with diff shows what a playbook would change on each host before you apply it. I wrote about using it for drift in Detecting configuration drift with Ansible check mode. The same run before a change tells you whether the change does only what you expect, or whether it will also “fix” some drift nobody knew about.

5. Staged and canary rollouts

Do not apply a change everywhere at once. Roll it out in stages, and let each stage prove itself before the next.

A typical shape:

  1. One instance or host (the canary). Long enough to see errors, crashes or resource changes.
  2. A small slice, a few percent of traffic or one zone.
  3. A larger slice, then the rest, often one region or failure domain at a time.

For the canary to be useful, you need to compare it with something. Watch the canary against the hosts still on the old version, over the same period, using the same signals: error rate, latency percentiles, saturation, crash or restart counts. A canary that looks “fine” on its own can still be measurably worse than its neighbours.

Also decide in advance what “bad” means. If you only decide after you see the graphs, it is easy to talk yourself into carrying on. Write the abort criteria down, and automate them where you can.

Config changes deserve the same treatment as code. A one-line config change pushed globally at once is one of the most common ways to turn a small mistake into a large outage.

6. Rollback switches and feature flags

The fastest rollback is one that does not need a deploy.

  • Feature flags let you ship code dark and turn behaviour on gradually, then off again in seconds.
  • Traffic switches let you shift load back to the old version or the old cluster.
  • Kill switches turn off a non-essential feature that is hurting the rest of the system.

A few rules make these work:

  • The switch must be tested. A rollback path that has never been exercised is a guess.
  • Turning it off must not depend on the thing that is broken. If the flag service needs the database that just fell over, it is not a switch.
  • Clean up old flags. Hundreds of stale flags become their own source of incidents.

Make “roll back first, debug second” the default. If a change might be the cause, undo it and see if things recover. You can investigate calmly once users are no longer affected.

7. Change windows and freezes

Change windows exist to make sure the right people are around when a change goes out. That is a good reason. “Changes only happen on Tuesday at 2am” is not, if nobody is awake to watch.

Useful practice:

  • Change when people who can respond are working and alert, not at the end of a long day.
  • Avoid stacking risky changes right before a weekend, a holiday or a known peak.
  • Use freezes around high-risk periods, but keep them short. Long freezes build up a backlog that all lands at once afterwards, which is the opposite of small batches.
  • Have an exception path for urgent fixes, with an extra reviewer.

8. Verify after the change

A change is not done when the command returns. It is done when you have confirmed the system is healthy.

  • Check the specific thing the change was meant to do. Did the new setting actually take effect?
  • Check the general health signals: errors, latency, saturation, and the alerts you would expect to fire if it went wrong.
  • Keep watching for a while. Some problems show up only at the next cron run, the next cache expiry or the next traffic peak.

Good alerts help here. If your alerts reflect user impact, as I described in Designing alerts that only fire when a human needs to act, they double as an automatic post-change check.

9. Communicate

Other people need to know what changed and when. When something breaks at 3am, the first question is usually “what changed recently?”.

  • Record every production change somewhere searchable: what, where, when, who, and how to roll it back.
  • Annotate dashboards with deploy and config change markers, so a graph shows the change next to its effect.
  • Tell the on-call engineer before a risky change, not after.

That record is what lets a responder follow a runbook step like “check recent changes”, which I covered in Writing a runbook you can use at 3am. It also gives the postmortem an accurate timeline.

10. Learn from bad changes

When a change does cause an incident, the postmortem should ask about the process, not just the change. Why did the checks not catch it? Why did the canary not show it? Why was rollback slow? Those answers usually point to the most useful action items. See Writing a postmortem that actually changes something.

Over time, each bad change should make the next one safer: a new pre-check, a better canary signal, a faster rollback.

11. A change checklist

Copy it into your change template and trim to fit.

## Change
- What is changing, and why:
- Systems / regions affected:
- Link to diff / plan / check-mode output:

## Before
- [ ] Diff reviewed by someone else
- [ ] Dry run / plan / check mode shows only expected changes
- [ ] Target system healthy, no active alerts
- [ ] No conflicting changes in progress
- [ ] On-call informed

## Rollback
- How to roll back:
- Rollback tested? (yes / no)
- Anything not reversible, and how that is handled:

## Rollout
- Stages (canary -> small slice -> rest):
- Signals to watch, compared with the old version:
- Abort criteria:

## After
- [ ] Intended effect confirmed
- [ ] Error rate, latency, saturation normal
- [ ] Change recorded with time and owner

12. Summary

Know how to undo every change before you make it. Keep changes small. Check the diff and do a dry run. Roll out in stages and compare the canary with the old version against criteria you wrote down beforehand. Keep a tested rollback switch, and use it first when in doubt. Change when people can watch, verify afterwards, and record what you did. None of this stops bad changes from happening. It makes them small, short and easy to explain.

References

  1. Google SRE book, Release Engineering.
  2. Google SRE book, Reliable Product Launches at Scale.
  3. Google SRE workbook, Canarying Releases.
  4. Google SRE workbook, Configuration Design and Best Practices.
  5. Martin Fowler, Canary Release.
  6. Ansible documentation, Validating tasks: check mode and diff mode.