Why you need it
To put a new version live, the simple way is to stop every copy of the app and start new ones. Between the stop and the start, nothing is answering, and every visitor in that gap gets an error. Do that a few times a day and the shop is often down.
Think of it like this
Painting a long fence while people walk past it. You do one section at a time, so there is always fence standing, and in the middle it is half old colour and half new.
Where you’ll find it
- Kubernetes: A Deployment replaces its copies a few at a time by default, and waits for each new one to be ready.
- AWS: Amazon ECS rolling updates swap old tasks for new ones while keeping a minimum number running.
- Google Cloud: Managed instance groups roll a new machine image across their servers a few at a time.
What to know first
Copies behind one address. The app runs as several identical copies, and a load balancer shares visitors between them. See Load balancing.
Ready. A copy that has started and answers its health check. Only then should it get visitors. See Health checks and heartbeats.
How it works
- Stopping everything is the problem. Ben stops both old copies, and for the seconds it takes new ones to start, every visitor gets an error. This is the first picture in the animation.
- Replace one copy at a time. Take one copy out and start a new one in its place. The other copies keep answering visitors meanwhile. This is the rolling deploy in the animation.
- Wait until the new copy is ready. The load balancer sends nothing to the new copy until its health check passes. Then the next old copy is replaced, and the next, until every copy is new.
- Old and new answer together. In the middle of a roll, some visitors are answered by the old version and some by the new. So both versions must work with the same database and the same requests. See Schema migrations (expand and contract).
- Keep enough copies. While one copy is out, the others carry its share. If they cannot, many tools start the new copy first and only then stop an old one.
An example
A shop runs 4 copies. Each one takes 30 seconds to start and pass its health check.
Stop all and restart: about 30 seconds where every visitor gets an error.
Rolling, one at a time: the deploy takes about 2 minutes, 3 of 4 copies always answer, and no visitor gets an error.
Further reading
- Performing a rolling update, Kubernetes docs. A short, picture-led walk through one copy being replaced at a time. Start with this one.
- Automating safe, hands-off deployments, AWS Builders' Library. How Amazon rolls changes out in small steps and stops when something looks wrong.
- Deployments: rolling update, Kubernetes docs. The two settings that decide how many copies may be missing or extra during a roll.