Releasing and running it · lesson 6 of 10
Ideas in this lesson
ABlue-greentwo copies; switch traffic between them
BCanaryrelease to a few users first, and watch
CFeature flaga switch that turns new code on or off without a deploy

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

Rollout strategies
StrategyHowIf it goes wrong
Big bangEveryone moves to the new version at onceEveryone is affected, and going back means another deploy
Blue-greenTwo identical production copies. The new version goes on the idle one, is checked, then traffic switches overSwitch traffic back: seconds, because the old version is still running
CanarySend a small share of users to the new version first, watch, then widenOnly the small group is affected, and the rollout stops
Feature flagDeploy the code switched off; turn it on later, for some or all usersTurn 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:

  1. 7:00 1.3.0 goes to all six barangays at once.
  2. 7:40 About 1 in 25 texts gets no reply. Nobody is watching closely: it’s Monday.
  3. 8:20 Calls come in from three health centres. The team starts looking.
  4. 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:

  1. Before 2012 Old code left in place
1 of 6 Before 2012. Knight Capital, a large US share trader, has an old feature called “Power Peg” in its order-routing system. It hasn’t been used since 2003, but its code is still on the servers, switched off by a flag.
Which practice from this stage would most directly have stopped it?

Spot the trap: Friday at 5 p.m.

Spot the trapKap. Ernesto

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

How does a blue-green deployment make going back fast?
What do feature flags separate?
Release 1.3.0 renames a database column. Why does that make rollback hard?

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.

All sources for Simple Software Development