Part 10 · Architecture & Deployment
CI/CD & Deployment Strategies: Blue-Green and Canary
Friday-evening deploys that need three people and a prayer are optional. CI that catches problems before merge, continuous delivery vs deployment, rolling, blue-green and canary releases — with a simulator — feature flags, zero-downtime database migrations and the DORA metrics.
On this page
The Problem
Friday evening, release night. The team has collected three weeks of changes into one big release. The steps are manual: copy files, run a script, restart servers, and hope it works. At 11 PM, the new version goes live on every server at once. Checkout breaks. Nobody is sure which of the 140 changes caused it, and rolling back takes two hours because the database was changed too.
Everyone is afraid of deploying (putting new code on the servers), so they deploy less often. This makes each release bigger and riskier. It is a bad circle that keeps getting worse.
Remember from post 48: most incidents start with a change. The answer is not to change less. The answer is to change in small, automatic, safe steps that you can undo. This is what CI/CD and modern deployment strategies are for. CI/CD means Continuous Integration and Continuous Delivery (or Deployment). A deployment strategy is a plan for how new code reaches users.
The Core Idea
Think about how a big restaurant chain launches a new dish.
- Continuous Integration is when the head chef tastes and checks every chef's small recipe changes every day, and does not wait a month for them to pile up.
- Canary release is offering the new dish at one restaurant first. If customers love it, try it at 10 restaurants, then everywhere. If they do not, take it away quickly, and only a few customers were affected. (The name comes from canary birds in coal mines, which warned miners of danger early.)
- Blue-green deployment is setting up a complete second kitchen with the new menu, and when it is ready, switching the customer entrance to it. If anything goes wrong, you switch the entrance back to the old kitchen at once.
- Feature flags are like having the dish on the menu, but hidden until the manager flips a switch. Or the dish is shown only to staff first.
How It Works
Part 1: Continuous Integration (CI)
CI (Continuous Integration) means developers merge small changes into the main branch often (at least daily), and every change is built and tested automatically. The main branch is the shared line of code that everyone's work joins. A pipeline is the list of automatic steps that run for each change.
Lint is a tool that reads your code and warns about style problems and likely mistakes. Static analysis is a tool that checks code for bugs without running it. A unit test is a small automatic check of one function. A container registry is a server that stores built container images.
- 1Developer pushesa branch or pull request
- 2Buildcompile, bundle
- 3Lint & static analysis
- 4Unit tests
- 5Integration / contract tests
- 6Security scansdependencies, secrets, SAST (scans your code for bugs without running it), image scan
- 7Image builttagged with the commit SHA, pushed to the registry
- 8Merge allowedor ❌ fix it before merging
Good CI practices:
- Trunk-based development: keep branches short (hours to a couple of days) and merge them to main often. Branches that live a long time cause big merge conflicts (two people changed the same code in different ways).
- Fast pipelines: aim for minutes, not hours. Slow CI makes people save up changes and merge them in big groups.
- Keep main always ready to release. If the build breaks, fix it at once (or undo the change that broke it).
- Build once, promote the same artefact. An artefact is the file you build, such as a container image. The exact same image (named by its commit SHA, the unique ID of a commit, or by its digest, post 55) moves through test → staging → production. Do not rebuild it for each environment. "Promote" means move it to the next environment.
- Automatic tests at several levels: many fast unit tests (test one small piece), fewer integration tests (test pieces working together), and a few end-to-end tests (test the whole app like a user). This shape is called the "test pyramid".
- Security checks built in (post 52).
Part 2: Continuous Delivery vs Continuous Deployment
- Continuous Delivery: every change that passes the pipeline is ready to deploy to production at any time, but a person clicks the button.
- Continuous Deployment: every change that passes the pipeline goes to production automatically, with no manual step.
Both need strong automatic tests, monitoring and safe rollout strategies. We look at those next.
A typical pipeline:
- Commit
- CIbuild, test, scan
- Stagingautomated checks
- Production canarywaves, bake time (waiting and watching)
- Full rolloutor automatic rollback
Part 3: Deployment strategies
1. Recreate (stop everything, start new)
Recreate is a strategy that stops all the old instances and then starts the new ones. A rollback means going back to the previous version. The blast radius is how many users a bad change can hurt.
- Beforev1 v1 v1
- Stop alldowntime starts
- Start newv2 v2 v2
- Problem?roll back = the same outage again
- ✅ Simple, and old and new versions never run together.
- ❌ Downtime. This is only acceptable for dev environments or systems with planned maintenance windows (times when users expect the service to be off).
2. Rolling update (replace instances gradually)
v1 v1 v1 v1 → v2 v1 v1 v1 → v2 v2 v1 v1 → v2 v2 v2 v1 → v2 v2 v2 v2- ✅ No downtime, and no extra full environment is needed. It is the default in Kubernetes (post 56).
- ❌ Old and new versions run at the same time, so they must be compatible (APIs, database schema, which is the layout of the tables, and message formats).
- ❌ To roll back, you go backwards through the same process, which is not instant.
3. Blue-green deployment
Blue-green deployment is a strategy that keeps two identical copies of production and moves users from one to the other in one step. Run two identical production environments. Blue is live, green gets the new version. You test green, then switch all traffic at the router or load balancer (the part that sends users to servers).
1% → 5% → 25% → 50% → 100%, checking error rates at every step. A bug caught at 1% hurts one user in a hundred.
- ✅ Instant switch and instant rollback (you just switch the router back).
- ✅ You can test the new version in an environment like production before it gets real traffic.
- ❌ Double the resources during the deploy.
- ❌ All users move at once, so a bug hits everyone until you switch back.
- ❌ Shared databases still need schema changes that work with both versions (see Part 5).
4. Canary release
A canary release is a strategy that sends the new version to a small group of real users first. A rolling update replaces old instances with new ones a few at a time. Send a small percentage of real traffic to the new version, watch the metrics, and increase gradually:
Step 1: 95% → v1 5% → v2 (canary) watch errors, latency, business metricsStep 2: 75% → v1 25% → v2 still healthy?Step 3: 50% → v1 50% → v2Step 4: 100% → v2 ✅ done At ANY step, if metrics worsen → send 100% back to v1 automatically- ✅ Limits the blast radius. A bug affects only a small share of users, for a short time.
- ✅ Real production traffic tests the release. This finds problems that staging (a copy of production used for testing) never shows.
- ✅ Works well with automated analysis: compare the canary's error rate and latency with the baseline (the old version), and roll back automatically if the canary is worse.
- ❌ You need good traffic routing (a load balancer is a server that spreads requests across servers; a service mesh is a layer that manages traffic between services; a gateway is the single entry point for requests) and good metrics (numbers that show how the system is doing, posts 46–47).
- ❌ Old and new versions run together, so they must be compatible.
Canary tips:
- Choose what to watch: error rates, p99 latency (the time that 99 out of 100 requests beat), crash rates, and business metrics (checkout success, sign-ups).
- Bake time: wait long enough at each step to catch slow problems, like memory leaks (a program that slowly uses more and more memory).
- For big platforms, roll out in waves: one server → one AZ (availability zone) → one region → all regions. A bad change then never hits everything at once.
5. Shadow (dark) traffic
Send a copy of real production requests to the new version, but do not send its answers to users. Compare its results and speed with the current version.
- ✅ Tests with real traffic and no effect on users.
- ❌ Doubles the load, and you must prevent side effects. The shadow copy must not send emails, charge cards or write to real data.
6. A/B testing
A/B testing works like a canary, because it also splits traffic. But the goal is different. The goal is product experiments: "does version B get more people to buy (conversions)?". It is usually controlled by feature flags, and you measure business results over days or weeks.
Part 4: Feature flags, separating deploy from release
Deploying code (putting it on servers) and releasing a feature (letting users see it) do not have to happen together. A feature flag (or feature toggle) is a switch in your code that turns a feature on or off without a new deploy. The new code goes out turned off, and you turn it on step by step:
if (flags.isEnabled("new-checkout", { userId, country })) { return newCheckout(req);}return oldCheckout(req);Uses:
- gradual rollout: your own staff → 1% of users → 10% → everyone,
- targeting: by country, plan, device or beta testers,
- kill switches: a kill switch is a flag that turns off a broken or costly feature at once, without a deploy (post 44),
- trunk-based development: merge unfinished work safely, because it is hidden behind a flag.
Flag hygiene:
- Remove old flags after the full rollout. Hundreds of old flags become flag debt: confusing code and combinations that nobody tested.
- Give each flag an owner and an expiry date.
- Remember that flags themselves are changes. Turning one on for everyone is the same as a release, so watch it like one.
Tools include LaunchDarkly, Unleash, Flagsmith, OpenFeature (an open standard that works with any vendor), and systems that companies build themselves.
Part 5: Database changes without downtime
You can roll back code in seconds. Database schema changes often cannot be rolled back. (A schema is the structure of the database: its tables and columns.) During rolling, canary and blue-green deploys, old and new code run at the same time against the same database. So schema changes must be backward compatible, which means the old code still works with them. Use the expand and contract pattern (also called parallel change):
Example: renaming a column name to full_name
- 1 · Expandadd full_name (nullable, so it may be empty); old code ignores it
- 2 · Dual writedeploy code that writes name and full_name, still reads name
- 3 · Backfillbackfill: copy the existing values in small batches
- 4 · Switch readsdeploy code that reads full_name, still writes both
- 5 · Contractstop writing name
- 6 · Dropremove the old column — every step was backward compatible
Every step is safe to roll back to the step before it.
Other rules:
- Never drop or rename columns in the same deploy as the code change. (To drop a column is to delete it.)
- Run large migrations online: in small batches, with tools made for big tables. This avoids long table locks (times when nobody else can use the table).
- Take a backup (or check that point-in-time recovery works, post 45) before risky migrations.
Part 6: Automated rollback and safety nets
- Health-based auto-rollback: if the error rate or latency goes past a set limit during rollout, roll back automatically. Nobody needs to wake up at 3 AM.
- Deployment windows and freezes: do not make risky changes during busy times (a big sale), or when the error budget is used up (the amount of failure your reliability goal allows, post 47).
- Deploy markers on dashboards: show exactly when each version went out. Then you can link an incident to a change quickly (post 48).
- One-click rollback: always know how to go back to the previous version, and practise it.
- GitOps: a way of running systems where the desired state is stored in Git, and tools like Argo CD or Flux make the cluster match it. Deploying means merging a pull request, and rolling back means reverting a commit (undoing it).
Part 7: Measuring delivery performance, the DORA metrics
The DORA research programme (DevOps Research and Assessment), described in the book Accelerate, found that high-performing teams are both faster and more stable. It uses four key metrics (numbers you can measure):
| Metric | Question | Elite teams (roughly, in older DORA reports) |
|---|---|---|
| Deployment frequency | How often do you deploy to production? | On demand, many times per day |
| Lead time for changes | How long from commit to running in production? | Less than a day |
| Change failure rate | % of deploys causing failures | Low |
| Time to restore service | How fast do you recover from a failure? (Newer reports call this "failed deployment recovery time".) | Less than an hour |
The key idea: speed and stability are not opposites. Small, frequent, automatic changes that you can observe are safer than big, rare, manual ones. (Later DORA reports added more measures, such as reliability, and stopped using fixed "elite" levels. But these four remain the core.)
Trade-offs
| Strategy | Downtime | Rollback speed | Extra resources | Blast radius | Complexity |
|---|---|---|---|---|---|
| Recreate | ❌ Yes | Slow | None | Everyone | Lowest |
| Rolling | ✅ None | Medium | Little | Grows gradually | Low |
| Blue-green | ✅ None | ✅ Instant | ❌ 2× during deploy | Everyone at switch | Medium |
| Canary | ✅ None | ✅ Fast | Little | ✅ Small | Higher (routing + metrics) |
| Shadow | ✅ None | N/A (no user impact) | ❌ Extra load | ✅ None | High |
- More automation gives faster and safer releases, but you must first spend time and money on tests, pipelines and monitoring.
- Continuous deployment gives the fastest feedback, but you need very good tests and automatic rollback.
- Feature flags are flexible and give you instant kill switches, but they bring flag debt and more code paths to test.
In the Real World
Amazon's deployment frequency. Amazon engineers have said that they deploy to production very often across many services. A talk from 2011 famously said there was a deploy every few seconds on average. This works because each team owns small services and uses automatic, staged pipelines. The AWS Builders' Library article on "automating safe, hands-off deployments" describes the wave-based rollouts (one box, one AZ, one region at a time) and the automatic rollbacks used at Amazon.
Chrome's release channels. Google Chrome ships through Canary, Dev, Beta and Stable channels. Each new version is used first by a small group of willing testers, then by larger groups, and only then by everyone. It is canary releasing for software on billions of devices.
Netflix's automated canary analysis. Netflix, together with Google, open-sourced Kayenta, a tool that uses statistics to compare a canary's metrics with a baseline. It decides automatically whether it is safe to continue the release. It works with Netflix's Spinnaker deployment platform.
Etsy and Facebook. Etsy became known for deploying dozens of times a day with a simple one-button tool (Deployinator) and strong monitoring. Facebook used feature flags (its Gatekeeper system) to release features to employees first, then to small percentages of users. This separated deployment from release.
The CrowdStrike incident (July 2024). A faulty content update for CrowdStrike's security software was sent to a huge number of Windows computers at the same time. It crashed millions of machines worldwide (post 9). Afterwards, the company promised to use staged, canary-style rollouts for such updates. It is a painful reminder that every kind of change, including configuration and content, needs progressive delivery (slow, step-by-step release).
Interview Questions
Q1Continuous delivery vs continuous deployment?
Continuous delivery keeps every change ready to release. It has passed the pipeline and can be deployed with one click, but a person decides when. Continuous deployment sends every change that passes the pipeline to production automatically.
Q2Compare rolling, blue-green and canary deployments.
Rolling replaces a few instances at a time. It needs no extra capacity, but two versions run together and a rollback means deploying again. Blue-green runs a full second environment and switches the router. Rollback is instant, but you need double the capacity during the switch. Canary sends a small percentage of traffic to the new version and raises it while the metrics stay healthy. It has the smallest blast radius, but it needs good metrics and a way to split traffic.
Q3What are feature flags for?
They separate deploy from release. You ship the code turned off ("dark"), then turn it on for staff, for a percentage of users or for one region. You can switch it off at once without a deploy. Flags also work as kill switches. Old flags must be removed so they do not become debt.
Q4How do you change a database schema with zero downtime?
Use expand and contract. Add the new column in a way the old code can ignore. Deploy code that writes to both. Backfill the old rows. Switch reads to the new column. Stop writing the old one, and only then drop it. Every step in between must work with both the old and the new code, because both run during a rollout.
Q5What are the DORA metrics?
Deployment frequency, lead time for changes, change failure rate and time to restore service. Elite teams deploy often with short lead times, and still keep failure rates low and recovery fast. Speed and stability go together.
Q6What should trigger an automatic rollback?
Health signals that are compared with the old version during the canary or bake period. These are the error rate, latency percentiles, crash rates and key business metrics like checkout success. Rolling back should be one fast action that you have tested.
Key Takeaways
- CI: merge small changes often, and automatically build, test and scan every change. Keep main releasable, and build once, promote the same artefact.
- Continuous Delivery means always ready to deploy. Continuous Deployment means automatically deployed. Both need safe rollouts.
- The strategies:
- Rolling: gradual, no downtime.
- Blue-green: instant switch and rollback, at the cost of double resources.
- Canary: small percentage first, then increase, with automatic rollback. It has the smallest blast radius.
- Shadow: test with copied traffic, with no user impact.
- Feature flags separate deploy from release (gradual rollout, targeting, kill switches), but need cleanup. Use expand-and-contract for zero-downtime database changes.
- Measure with the DORA metrics. Small, frequent, automated, observable changes are both faster and safer.
Further Reading
- Martin Fowler's articles "Continuous Integration", "BlueGreenDeployment", "CanaryRelease" and "ParallelChange", and Pete Hodgson's "Feature Toggles (aka Feature Flags)"
- The AWS Builders' Library article "Automating safe, hands-off deployments"
- The Site Reliability Workbook by Google (chapter "Canarying Releases")
- Continuous Delivery by Jez Humble and David Farley, and Accelerate by Nicole Forsgren, Jez Humble and Gene Kim
- The DORA research website
- The Argo Rollouts documentation, and the Netflix Tech Blog post on automated canary analysis with Kayenta
This wraps up Part 10. Next up, Part 11: Design It Yourself: Case Studies, starting with "A 5-Step Framework for Any System Design Problem".
Published by Jainik · Last updated · How these lessons are made
Keep learning
Part of the study guide
Related series