Releasing safely
Last updated
Every release is a small risk: something that passed every check can still go wrong in front of real users. Teams can't make that risk zero, but they can make it small and short: release to a few people first, keep the old version ready, and switch features on separately from deploying them. In this lesson you'll compare the ways to roll out a release, plan Pila's way back, and see what happened at Knight Capital when a release went out halfway.
By the end of this lesson you can
- Compare big-bang, blue-green and canary releases
- Use feature flags to separate deploying code from turning it on
- Plan a way back: rollback or roll forward, including for database changes
Ways to roll out
| Strategy | How | If it goes wrong |
|---|---|---|
| Big bang | Everyone moves to the new version at once | Everyone is affected, and going back means another deploy |
| Blue-green | Two identical production copies. The new version goes on the idle one, is checked, then traffic switches over | Switch traffic back: seconds, because the old version is still running |
| Canary | Send a small share of users to the new version first, watch, then widen | Only the small group is affected, and the rollout stops |
| Feature flag | Deploy the code switched off; turn it on later, for some or all users | Turn the flag off: no deploy needed |
The names come from mining and from colours. Miners carried a canary into the mine: if gas was there, the bird showed it first. Blue and green are just labels for the two copies.
A canary in one barangay
Pila now runs for six barangays. Release 1.3.0 changes how numbers are stored. Compare a big-bang release with a canary that sends only San Roque's texts to the new version for its first hour:
- 7:00 1.3.0 goes to all six barangays at once.
- 7:40 About 1 in 25 texts gets no reply. Nobody is watching closely: it’s Monday.
- 8:20 Calls come in from three health centres. The team starts looking.
- 9:05 A new deploy of the old version finishes. Hundreds of patients were affected.
Without a canary release with an automatic rollback: All six health centres were affected for over an hour, during the busiest time of the week.
Switch to the other side to compare.
A canary only helps if someone, or something, is watching the right signal. Lesson 7.7 is about choosing it.
Feature flags
A feature flag is a setting that switches code on or off while it runs. Jun can merge and deploy the half-finished vaccination reminders with the flag off; nobody sees them. When they're ready, Ate Cora's health centre gets them first, then everyone. If something's wrong, the flag goes off in seconds.
Flags separate two decisions: deploying (a technical step, any day) and releasing (a decision about users). Pete Hodgson's warning on Martin Fowler's site: flags are a debt (lesson 5.9). Each one doubles the paths through the code, so remove a flag as soon as its feature is fully on. And never reuse an old flag for a new purpose; step 5 shows why.
The way back
Before every release, the team answers: if this goes wrong, how do we get back?
- Rollback: return to the previous version. Fast and safe when the old version is still there (blue-green), or when the pipeline can redeploy it in minutes.
- Roll forward: fix the problem and release again. Sometimes it's quicker, but it means writing code under pressure.
Rolling back is hard when the database has changed. If 1.3.0 renames a column, 1.2.0 can't read the database any more. So teams change databases in steps that both versions can live with: add the new column first, write to both, move readers over, and only remove the old column in a later release, once nobody needs it. Martin Fowler calls this pattern parallel change, or expand and contract.
Knight Capital, 1 August 2012
A release that went out halfway, from the US Securities and Exchange Commission's order:
- Before 2012 Old code left in place
Spot the trap: Friday at 5 p.m.
It’s Friday at 5 p.m. before a long holiday weekend. Release 1.4.0 is approved. “Let’s get it out now,” says Kap. Ernesto, “so it’s ready when the centre reopens on Tuesday.”
What happens if…
Check what you learned
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- Martin Fowler: Blue Green Deployment: two production environments, one live
- Danilo Sato: Canary Release (martinfowler.com): rolling out to a small group first
- Pete Hodgson: Feature Toggles (aka Feature Flags) (martinfowler.com): kinds of flags, and keeping them under control
- US Securities and Exchange Commission: In the Matter of Knight Capital Americas LLC, Release No. 70694 (2013): the official account of the 1 August 2012 deployment