Why you need it
Tests never catch everything. When a new version goes to every visitor at once and it is bad, every visitor gets the error. You want to find out on a few people first, not on all of them.
Think of it like this
Tasting one spoonful before you serve the whole pot. If it is too salty, only one spoon is wasted.
Where you’ll find it
- Argo Rollouts: Runs canary steps on Kubernetes: send a small share to the new version, pause, check, then grow it.
- Spinnaker: Netflix's deploy tool compares the canary with the old version automatically, using canary analysis.
- AWS: CodeDeploy deployment configurations include canary steps such as 10% first, the rest a few minutes later.
What to know first
Replacing copies. A deploy swaps old copies for new ones. See Rolling deploys.
Error rate. The share of answers that fail, watched on a graph. See Metrics and alerts.
Share of visitors. The load balancer can send, say, 1 visitor in 10 to one place and the other 9 elsewhere.
How it works
- All at once is the risk. Every visitor is moved to the new version together. It is bad, and all ten get an error. This is the first picture in the animation.
- Send a few visitors first. Start one copy of the new version, the canary, and send it only 1 visitor in 10. The other 9 stay on the old version.
- Compare, then decide. A program watches the canary's errors and speed next to the old version's. If the canary is clearly worse, it is taken away, and only the few visitors it served saw the problem. This is the canary being removed in the animation.
- A good canary grows step by step. If it looks healthy, it gets more: 1 in 10, then 5 in 10, then all. More new copies are started as its share grows.
- Real numbers are smaller. Big sites often start nearer 1 visitor in 100, and wait long enough at each step to see real traffic, often several minutes.
An example
A shop gets 10,000 visitors an hour, and a new version fails for everyone who uses it.
All at once: in the 10 minutes before anyone notices, about 1,700 visitors get an error.
Canary at 1 in 100: about 17 visitors get the error in those 10 minutes, and the canary is taken away before the rest see it.
Further reading
- Canarying releases, Google, The Site Reliability Workbook. How Google sizes a canary, how long to wait, and what to compare. Start with this one.
- CanaryRelease, Danilo Sato, on martinfowler.com. A short description of the idea, and where the name comes from.
- Canary analysis, Spinnaker docs. How a machine decides whether a canary passed, so no human has to stare at graphs.