Canary releases explained: shipping to a few users first
A canary release routes a small share of live traffic to the new version first, and you promote it to everyone only if error rate and latency stay healthy.
- Updated Nov 27, 2026
- Markdown
Run a canary with weighted traffic, decide on promote or rollback from metrics, and know when canaries are the wrong tool.
- An app behind nginx or another reverse proxy
- A way to see error rate and latency
A canary release sends a small share of real traffic to the new version while everyone else stays on the old one. You watch error rate and latency on both. If the canary looks healthy you raise its share until it takes everything. If not, you set its share to zero and the damage stays small. It is a safer cousin of a normal deploy, at the cost of running two versions side by side.
How it works#
The name comes from the canary in a coal mine: a small early warning. The mechanism has four parts:
- Start the new version next to the old one, without removing the old one.
- Route a small percentage of requests to the new version at the proxy.
- Compare the new version’s error rate and latency with the stable one over a set period.
- Promote it to full traffic, or remove it and send everything back to the stable version.
Because the stable version keeps serving most users the whole time, rollback is just a routing change. That is faster than redeploying. See rollbacks for the other rollback methods.
Canary vs blue-green vs rolling#
- A rolling deploy replaces instances one by one. Users hit a mix of versions during the rollout, but you rarely control the exact share.
- A blue-green deploy prepares a full second environment and switches all traffic at once. Rollback is a quick switch back, but a bad release hits everyone.
- A canary keeps both live and moves traffic in small, controlled steps, so you learn from a slice of real users before committing.
The first two are compared in blue-green vs rolling deploys. Neither one replaces the aim of zero-downtime deploys: the canary is about risk, not just downtime.
An nginx weighted upstream#
This is an illustration, not a complete production setup. Run the stable and new versions as two containers on one Docker network, and give the new one a small weight:
upstream app {
server app-stable:8080 weight=9;
server app-canary:8080 weight=1;
}
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://app;
proxy_set_header Host $host;
}
}With weights 9 and 1, about one request in ten reaches the canary. The share is approximate and applies to requests, not users, so one visitor may see both versions. After editing the config, test and reload without dropping connections:
sudo nginx -t && sudo nginx -s reloadIf nginx runs in a container, run the same two commands with docker exec into that container. To promote, change the weights step by step, for example 5 and 5, then remove the stable server. To roll back, delete the canary line or set it to down, and reload.
What to measure#
Decide the pass or fail rules before you start, so you are not judging by feel:
- Error rate: the share of 5xx responses on the canary compared with stable.
- Latency: median and slow-tail response times from the proxy logs.
- Business signals: failed logins, failed payments or other app-specific errors.
- Resource use: memory growth or restarts of the canary container.
Add a label or header to canary traffic, such as a log field with the upstream name ($upstream_addr in nginx), so you can split the numbers. A health check on the canary stops obviously broken containers from receiving traffic, and external uptime monitoring catches wider problems. Keep the threshold values in config or a runbook, not in someone’s head.
Sticky sessions#
Weighted round-robin can send one user to different versions on different requests. That breaks apps that keep session data in memory, and it confuses users if the interface changes between clicks. Options: store sessions in a shared place such as Redis or the database, or make routing sticky. In nginx you can use ip_hash in the upstream, which ties a client address to a server, although it ignores weights in a simple way and clients behind one NAT share a fate. Cookie-based routing needs extra modules or a different proxy. Pick the approach that matches how your app handles state.
Database migrations#
Both versions use the same database at the same time. A migration that drops or renames a column breaks the stable version the moment it runs. Use the expand and contract pattern: first add new columns or tables in a way both versions tolerate, deploy the code that uses them, and only later remove the old structure once no old version is live. Test that the previous version still works against the new schema before you start the canary.
Check it worked#
Send a batch of requests and look at the split in the access log:
for i in $(seq 1 50); do curl -s -o /dev/null https://app.example.com/; doneThen count by upstream in the log, if you added $upstream_addr to the log format. You should see roughly the share you configured. Check the canary container’s own logs for errors:
docker logs --tail 50 app-canaryFinally compare error counts over your chosen window before changing any weights.
Edge cases and gotchas#
- Low traffic: With few requests, a 5 percent canary may see almost nothing. Raise the share or run longer, or the signal means little.
- Request vs user share: Weighted rotation splits requests. A single user may bounce between versions unless routing is sticky.
- Background jobs: Workers and scheduled jobs are not behind the proxy, so a canary of the web tier does not cover them.
- Caches: Responses cached by a CDN or browser can hide which version served them.
- Shared state: Cache formats, queue messages and file layouts must work for both versions at once.
- Cost of two versions: You run extra capacity during the canary, and incident debugging gets harder when two versions are live.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Canary gets no traffic | Weight is zero, or the container is down | Check the upstream, container health and nginx -t |
| Users see flipping behavior | Requests alternate between versions | Use shared sessions or sticky routing |
| Stable version errors after migration | Schema change not backward compatible | Roll back the migration step, use expand and contract |
| Cannot tell canary errors apart | Logs lack an upstream field | Add $upstream_addr to the log format |
| Reload fails | Config syntax error | Run nginx -t and fix before reloading |
Quick reference#
sudo nginx -t && sudo nginx -s reload
docker logs --tail 50 app-canary
docker compose up -d app-canary
docker compose stop app-canaryRelated lessons#
- Blue-green vs rolling deploys for the other two strategies.
- Rollbacks for undoing a release that went wrong.
- Zero-downtime deploys for avoiding gaps during a switch.
- What is a reverse proxy for the layer that splits traffic.
- Feature flags vs deploys for limiting exposure inside one version.
Next#
Continue with feature flags vs deploys.
Check what you learned
Frequently asked questions
What is a canary deployment?
It is a rollout where a new version receives a small percentage of production traffic while the old version serves the rest. If metrics look healthy you increase the share, otherwise you roll back.
What is the difference between canary and blue-green?
Blue-green switches all traffic from one full environment to another at once. A canary shifts traffic gradually, so a bad release affects only part of your users.
Can I do a canary release without Kubernetes?
Yes. Run the new version as a second container and give it a small weight in a reverse proxy such as nginx. Watch logs and metrics before shifting more traffic.
How long should a canary run?
Long enough to see a meaningful number of requests and any slow-building problems. The right time depends on your traffic and the kind of change, so decide it before you start.
Keep going: guides and tutorials
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.
- Roll Back a Failed Docker Deploy Without Downtime Ship a broken release on purpose, watch your users stay on the old version, then roll back with one command. Real commands, real output, self-hosted.
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.