System Design
10-Min Deep Dive

What is a Canary Deployment?

Canary Deployments: A Safe and Controlled Rollout of New Code

canary deployments, rolling updates, zero-downtime deployment, continuous delivery

As developers, we're always looking for ways to reduce the risk associated with deploying new code to production. One popular technique is a canary deployment, which allows us to rollout changes in a controlled and gradual manner. In this post, we'll dive into what a canary deployment is, how it works, and when you should use it.

What is a Canary Deployment?

A canary deployment is a deployment strategy that involves routing a small percentage of traffic to the new version of your application or service while keeping the majority of traffic on the old version. This allows you to test and verify the new code in production before switching all users over to it. The idea is inspired by the concept of sending a canary into a coal mine to check for toxic gases – if the canary comes out okay, it's safe for humans to enter.

How Does a Canary Deployment Work?

Here's an example of how you might implement a canary deployment using Kubernetes:

Let's say you have a web application that serves traffic from users all over the world. You want to deploy a new version of your app with some exciting new features, but you're not sure if it will work as expected.

  1. Setup: Create a new container or pod for the new version of your application.
  2. Route traffic: Use Kubernetes' built-in routing capabilities (such as Ingress or Service) to route 10% of incoming traffic to the new version.
  3. Monitor: Keep an eye on metrics and logs for both versions of your app, looking for any signs of trouble.
  4. Verify: If everything looks good, you can gradually increase the percentage of traffic routed to the new version.
  5. Flip: Once you're confident that the new version is working correctly, you can switch all traffic over to it.

Benefits of a Canary Deployment

Canary deployments offer several benefits:

  • Reduced risk: By testing in production with a small percentage of users, you can identify and fix issues before they affect everyone.
  • Improved reliability: With two versions of your app running concurrently, you can quickly roll back to the old version if something goes wrong.
  • Increased confidence: A successful canary deployment gives you peace of mind that the new code is working as expected.

When Should You Use a Canary Deployment?

A canary deployment makes sense when:

  • You're deploying a non-critical feature or bug fix, and you want to ensure it works correctly before switching all users over.
  • Your application has a large number of dependencies or integrations that need to be tested in production.
  • You're dealing with a complex or high-stakes deployment that requires extra caution.

TL;DR

A canary deployment is a safe and controlled way to rollout new code in production. By routing a small percentage of traffic to the new version, you can test and verify it before switching all users over. This strategy offers reduced risk, improved reliability, and increased confidence – making it a valuable tool in your continuous delivery arsenal.

Note: While this post focuses on Kubernetes, the concept of a canary deployment applies to any environment where you're deploying code to production.

Propagate this knowledge. Link copied automatically on click.
What is a Canary Deployment? - 10-Minute Engineering Brief | DevExCode | DevExCode