Practice this topic in a realistic system design interview
Suppose your application is running on ten servers, all using version 1. Your team has finished building version 2, tested it thoroughly, and is now ready to release it to production.
But deploying new code always comes with some risk. In fact, software releases are one of the most common causes of production incidents.
A deployment strategy is the plan for moving traffic from the old version to the new one. Each strategy makes different trade-offs between downtime, risk, cost, and rollback speed.
This chapter covers the most common deployment strategies, how each one works, where each one can hurt you, and how to choose between them.
The problem is that staging environments can never fully replicate production. Production has real users, real traffic, real data, and dependencies that may behave differently under load. So a bug that went unnoticed during testing might appear within seconds of deployment.
A live system is also not sitting still while you deploy. It has open connections, requests in flight, caches full of data, and background jobs in progress.
The challenge, then, is not just getting the new version into production. It is doing so in a way that minimizes the impact if something goes wrong. That is what deployment strategies help us achieve.
Every deployment strategy comes down to a few practical questions:
Each strategy handles these concerns differently, and no single approach is best at everything. Choosing the right one means understanding these trade-offs and deciding what matters most for your application.
The five strategies covered here are recreate, rolling, blue-green, canary, and shadow. After them, we'll look at feature flags, which work alongside all five.
The simplest deployment strategy is called recreate, sometimes also known as a big bang deployment.
The idea is straightforward:
This approach is easy to understand and implement. Since the two versions never run at the same time, you don't have to worry about compatibility between them.
But there's a major downside. From the moment you stop the old version until the new one is ready to serve traffic, your application is unavailable. And if version 2 contains a bug, every user is affected at once.
Rolling back isn't any easier. You have to stop version 2 and bring version 1 back, which causes another period of downtime.
Despite these limitations, recreate deployments can still work well for internal tools, batch jobs, or applications with planned maintenance windows. They are also used for some stateful systems where two versions cannot safely run at the same time.
For most user-facing services, though, we need an approach that keeps the application available during deployment.
A rolling deployment updates servers gradually instead of replacing everything at once.
Suppose our application is running on ten servers:
Since most servers keep handling traffic during the rollout, the application can stay available without downtime, as long as there's enough capacity.
This is the default deployment strategy on many platforms. Kubernetes, for example, uses rolling updates by default for Deployments. It lets you control two settings:
Together, these settings determine how quickly the deployment progresses and how much capacity remains available to handle traffic.
Rolling deployments have two important trade-offs.
The first is that old and new versions run at the same time. Halfway through the rollout, some servers are still running version 1, while others have already switched to version 2. A user might hit version 2 on one request and version 1 on the next. So both versions need to be compatible with the same requests and data. That includes API formats, database schemas, cached values, and messages on queues.
The second is rollback speed. Suppose we've already upgraded eight servers when we discover a bug in version 2. To roll back, we have to repeat the rolling process in reverse, moving servers back to version 1 in batches. This takes time, and users may keep hitting the broken version until the rollback finishes.
So what if we could switch back to the previous version in just a few seconds?
That's what blue-green deployments are designed for. Instead of upgrading servers one by one, we maintain two separate environments:
At first, green doesn't receive any real user traffic, so we can deploy the new version, warm it up, and run smoke tests to make sure everything works as expected.
Once we're confident, we switch the load balancer or router to send all production traffic to green. This switch can happen in just a few seconds.
Meanwhile, the blue environment stays running with the old version. If something goes wrong with version 2, we route traffic back to blue, and users are on the previous version almost immediately.
Blue-green lets us release new versions without downtime and roll back much faster than the strategies we've seen so far. But there are a few trade-offs.
So while rollback is fast, the potential impact is still large. What if we could reduce that risk by testing version 2 with a small group of real users first?
A canary release takes a more cautious approach.
The name comes from the canaries that miners once carried into coal mines. If a bird showed signs of distress, it warned the miners that the air was unsafe before they were seriously affected.
Canary releases follow a similar idea. Instead of sending all production traffic to version 2, we deploy it alongside version 1 and send only a small percentage of traffic to it, say 1%. The other 99% keeps using version 1.
We then monitor the new version closely, comparing its error rates, latency, and important business metrics with those of the old version.
If everything looks good, we gradually increase the traffic to version 2: 1% → 5% → 25% → 50% → 100%.
If something goes wrong at any stage, we route traffic back to version 1. This lets us catch problems early, before they affect a large number of users.
Canary releases work well, but they depend on a few things.
So canary releases limit the impact of bugs, but some real users still see the new version. What if we could test it with real production traffic without affecting any users at all?
That's what a shadow deployment, also known as traffic mirroring, lets us do.
Version 1 keeps serving all users as usual. At the same time, we send a copy of each incoming request to version 2. The new version processes these requests, but its responses are discarded. Users only get responses from version 1, so their experience doesn't change.
This lets us see how version 2 performs under real production traffic without exposing users to its responses. We can compare latency, error rates, and even the responses produced by both versions. It is a good fit for rewrites of performance-sensitive code such as search, ranking, or recommendations.
There's one important risk: side effects. Suppose a mirrored request processes a payment or places an order. If version 2 also charges the customer or sends a confirmation email, that action could happen twice.
To avoid this, shadow deployments work best for read-only operations. For requests that involve writes, we need to isolate the side effects, for example by replacing external calls with stubs or sending writes to test storage.
So far, we've looked at strategies that control how new code is deployed across servers. There's another way to reduce risk: controlling which features users can access. This is where feature flags come in.
With feature flags, we deploy the new code to production but keep the feature disabled behind a flag. The code is already running on the servers, but users keep seeing the old behavior.
When we're ready, we enable the feature for internal users first, then a small percentage of customers, and eventually everyone. If something goes wrong, we turn the flag off without redeploying anything.
This separates two ideas that are easy to mix up:
Feature flags work alongside any of the deployment strategies we've discussed. For example, a team might use a rolling deployment to ship the new code, then gradually enable the feature with a flag.
So how do you choose the right deployment strategy?
Start with downtime. How much downtime can your application tolerate? If a short maintenance window is acceptable, recreate might be all you need.
Then think about the impact of a failed release. For something like an internal dashboard, a rolling deployment with proper health checks is usually enough. For critical services like checkout or payment APIs, you might prefer a canary release to limit the number of affected users, or blue-green for faster rollbacks.
Consider your monitoring. A canary release is only useful if you can reliably compare the performance of the two versions. Useful signals include error rate, latency (p50, p95, p99), saturation such as CPU or queue depth, and business metrics like checkout success rate. A process being "up" is not enough; real requests need to succeed.
Check database compatibility. Rolling, blue-green, and canary all run old and new code against the same database at some point. Schema changes need to be backward compatible: add new columns before reading them, and drop old columns only after the old code is gone.
| Situation | Reasonable Strategy |
|---|---|
| Internal tool, batch job, or maintenance window is acceptable | Recreate |
| Stateless service with several instances, like an internal dashboard | Rolling |
| Critical API where rollback speed matters most | Blue-Green |
| Critical service like checkout, with good per-version metrics and enough traffic | Canary |
| Rewrite you want to test on real traffic, with side effects isolated | Shadow |
| Risky feature you want to turn on gradually | Any deployment + feature flag |
In practice, teams often combine several strategies. For example, you might use rolling updates to deploy the new code, gradually increase traffic to the new version with a canary release, and control individual features with feature flags.
Each step catches a different kind of problem. Staging catches obvious bugs, the canary catches problems that only show up under real traffic, the rolling deploy finishes the rollout without a second full fleet, and the flag lets you turn the feature on when you're ready.
Deployment strategies determine how we move from an old version of an application to a new one while managing risk.
Whichever strategy you choose, backward compatibility, reliable health checks, and good monitoring are essential for safe deployments.
10 quizzes