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
- AWS: CodeDeploy blue/green deployments start a new set of servers, move the load balancer to it, and keep the old set for a while.
- Azure: App Service deployment slots run the new version in a second slot, then swap the two.
- Cloud Foundry: Its docs describe blue-green deployment as moving the app's address from the old app to the new one.
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
- 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.
- 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.
- 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.
- 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.
- 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
- BlueGreenDeployment, Martin Fowler. The short original description of the idea, and where the name comes from. Start with this one.
- Blue/Green Deployments on AWS, AWS whitepaper. Several real ways to make the one move, with their trade-offs.
- Using blue-green deployment to reduce downtime, Cloud Foundry docs. A small worked example you can follow command by command.