Home DevOpsBlue-Green and Canary Deployments Explained: Strategies, Examples, and When to Use Each

Blue-Green and Canary Deployments Explained: Strategies, Examples, and When to Use Each

by Knowledge Base Linux
Blue-Green and Canary Deployments Explained — Blue-Green and Canary Deployments Explained: Strategies, Examples, and Whe

Every deployment strategy answers the same question: how do you release new code without downtime, and how do you recover in seconds when the release is bad? A plain rolling restart answers it poorly. Two strategies dominate modern DevOps practice, and this article explains blue-green and canary deployments with concrete examples so you can choose between them with confidence. This article covers Blue-Green and Canary Deployments Explained in detail.

How Blue-Green Deployment Works – Blue-Green and Canary Deployments Explained

You run two identical production environments, called Blue and Green. Only one of them receives live traffic at any moment. Suppose Blue is live on version 1.0. You deploy version 1.1 to the idle Green environment, run smoke tests against it privately, and then switch the router or load balancer so all traffic goes to Green. Blue stays untouched as a warm standby.

  • Instant rollback: if Green misbehaves, switch traffic back to Blue. Rollback takes seconds and involves no redeployment.
  • Full-scale testing: the new version runs in a true production-like environment before any user sees it.
  • Higher cost: you need double the infrastructure, at least during releases.
  • Database care required: both environments share one database in most setups, so schema changes must stay backward-compatible with the old version (the expand-and-contract pattern: add new columns first, remove old ones in a later release).

On Kubernetes, blue-green is often implemented as two Deployments behind one Service; switching means changing the Service selector label from version: blue to version: green. Behind Nginx or a cloud load balancer, it is an upstream or target-group switch.

How Canary Deployment Works – Blue-Green and Canary Deployments Explained

A canary release sends the new version to a small slice of real traffic first, named after the canaries miners carried to detect danger early. A typical progression is 5% of requests for fifteen minutes while you watch error rates and latency, then 25%, 50%, and finally 100%. If metrics degrade at any step, you stop and route everyone back to the stable version, having exposed only a handful of users.

  • Real-world validation: real users and real data exercise the new version, catching issues synthetic tests miss.
  • Gradual risk: a bad release affects a small percentage of traffic, not everyone.
  • Needs good observability: without dashboards and alerts comparing canary versus stable, you are guessing.
  • More moving parts: traffic splitting requires support in your load balancer, service mesh, or ingress controller.

With plain Nginx you can approximate a canary using the split_clients directive, which consistently hashes each visitor into a bucket:

split_clients "${remote_addr}" $pool {
    10%  "canary";
    *    "stable";
}

upstream stable { server 10.0.0.11:8080; }
upstream canary { server 10.0.0.12:8080; }

server {
    location / {
        proxy_pass http://$pool;
    }
}
Blue-green and canary deployments - canary traffic split illustration

Blue-Green and Canary Deployments in Kubernetes with Argo Rollouts

On Kubernetes, Argo Rollouts replaces the standard Deployment controller and supports both strategies declaratively. A canary rollout looks like this:

strategy:
  canary:
    steps:
      - setWeight: 10
      - pause: { duration: 10m }
      - setWeight: 50
      - pause: { duration: 10m }
      - setWeight: 100

Rollouts can also query Prometheus during each pause and abort automatically if error rates spike, which removes the human babysitting from releases. This is where blue-green and canary deployments become practical for small teams, not just large platforms.

How to Choose Between Them

  • Choose blue-green when you need the simplest mental model, releases are infrequent, infrastructure is cheap or elastic, and instant full rollback matters more than gradual validation. It is also friendlier to monoliths and stateful services.
  • Choose canary when you deploy frequently, traffic is high enough that 5% is statistically meaningful, and you have monitoring capable of comparing versions. It shines for microservices and user-facing APIs.
  • Combine them: many teams blue-green between environments for staging confidence and canary within production. The strategies are complements, not rivals.

Troubleshooting and Common Pitfalls

Users see mixed versions during a release

Long-lived sessions can straddle a switch. Use sticky sessions carefully, keep versions compatible at the API level, and prefer canary steps that pin a user to one variant.

Database migrations break the old version

Both strategies keep old code alive during the transition, so migrations must be backward-compatible. Expand first (add), migrate data, then contract (remove) in a later release.

Canary analysis cries wolf

Compare the canary against the stable version over the same window, not against historical averages, and give each step enough traffic and time before judging.

Decide Your Rollback Triggers Before You Release

Both strategies fail in practice when teams improvise decisions mid-incident. Agree on the numbers in advance: for example, roll back if the 5xx error rate exceeds 1% for five minutes, if p95 latency grows by more than 30% versus the stable version, or if a key business conversion metric drops outside its normal band. Write these triggers in the release checklist and, better, encode them in your rollout tooling so the system aborts automatically. Also decide who can call a rollback; in a healthy culture, anyone on the release can pull the cord without a meeting. Record every aborted release and review it blamelessly: an aborted canary is the strategy working, not a failure of the team. Over time these records show which services need better tests or smaller releases, which is the real long-term payoff of disciplined deployment strategy.

Conclusion

Blue-green and canary deployments both eliminate the “deploy and pray” pattern: blue-green with a clean all-at-once switch and instant rollback, canary with gradual, metric-driven exposure. Pick based on your release frequency, traffic, and observability maturity, and automate the analysis wherever possible. The Argo Rollouts documentation is the best next step for hands-on Kubernetes examples, and pairing rollouts with the monitoring stack from our Prometheus and Grafana guide makes canary analysis genuinely reliable.

Related reading: GitHub Actions Matrix Builds: Test Every Version Fast

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.