Blue-green deploys

Why you need it

Once a rolling deploy has finished, every copy runs the new version. If that version turns out to be bad, the old one is gone, and going back means another whole deploy, with visitors getting errors the entire time.

Think of it like this

Keeping your old phone in a drawer for a week after you buy a new one. If the new phone breaks, you just pick the old one up again. Nothing to set up.

Where you’ll find it

What to know first

Replacing copies. A normal deploy swaps old copies for new ones, one by one. See Rolling deploys.

Set. All the copies of one version together. Here there are two sets: the old one and the new one.

How it works

  1. Going back is slow. The new version breaks and every copy runs it. Going back is another deploy, with errors meanwhile. This is the first picture in the animation.
  2. Start a full new set beside the old one. Leave the old copies running. Start a whole new set of copies with the new version next to them, and check it while no visitor uses it yet.
  3. One move sends every visitor over. The load balancer is pointed at the new set in one step. Every visitor now gets the new version. The old set stays, idle. This is the arrow swinging over in the animation.
  4. One move back. If the new version breaks, point the load balancer back at the old set. It never left, so this takes seconds. This is the arrow swinging back.
  5. The cost. For a while you run twice the servers. And both sets share one database, so the new version must not change it in a way the old one cannot read. See Schema migrations (expand and contract).

An example

A shop runs 6 copies, and a deploy of 6 new copies takes 10 minutes.

Rolling deploy, then the new version breaks: going back is another 10-minute deploy, with errors the whole time.

Blue-green: the old 6 copies are still running. Moving the load balancer back takes about 5 seconds.

Further reading