Stage 4 · Reliability · Medium · 15 min
CI/CD and safe deployments
How a change gets from a commit to production. A pipeline builds and tests it, there are four ways to ship it, and a rollback undoes it.
What each interview level is expected to know
Learn first: Load balancing and health checks, Observability, SLOs and error budgets
In AI systems: Prompt, retrieve or fine-tune
After this lesson you can:
- Follow a change from commit to production through one pipeline.
- Compare rolling, blue-green and canary releases, and feature flags.
- Work out how many users a bad canary affects, and plan a rollback that works.
Start here
See it in 60 seconds
From a commit to production
A pipeline carries every change through the same steps, from a saved commit to production, and a failed check stops it before users are touched.
Scene 1 of 7 · A commit starts it
A developer saves a change, called a commit, and the pipeline starts with no one pressing a button.
- Commit — saved change — healthy
- Build — makes package — healthy
- Tests — checks it — healthy
- Package — stored once — healthy
- Staging — practice copy — healthy
- Production — real users — healthy
- Commits
- 1
- Stopped by a test
- 0
- Reached production
- 0
- A commit starts it. A developer saves a change, called a commit, and the pipeline starts with no one pressing a button.
- Build one package. The build step turns the code into one package, the exact file that servers will run.
- Tests check the package. 240 automatic tests now run against that package, and nothing moves on until they finish.
- A failing test stops it. One test fails, so the pipeline stops here and production never sees this change.
- A fix is committed. The developer commits a fix, the pipeline builds a new package, and this time every test passes.
- Same package, staging first. The package that passed is stored once, and that same file is tried in staging, a practice copy of production.
- Production, a little first. Production gets that package a few servers at a time, so a missed bug reaches few users.
- Now you try. A unit test checks one service alone. An integration test runs services together. A bug sits between two services: checkout sends a price that payments cannot read. Which checks does your pipeline run? For example: Each service passes its own unit tests, so the bug ships. All 1,000 users in this example can hit it. A unit test checks one piece alone, so it cannot see a bug in how two pieces talk.
Scene 1 of 7: A commit starts it. A developer saves a change, called a commit, and the pipeline starts with no one pressing a button.
Key points
- A commit starts the pipeline by itself: build, test, package, staging, production.
- Build once: the package that passed the tests is the one that ships.
- A failed check stops the pipeline, and production keeps running the old version.
- Unit tests miss bugs between services, so add tests that run services together, and a canary.
In plain words
Say a developer fixes the checkout button and saves the change. That saved change is called a (Making a change final. A committed database write counts and will not be undone. In Git, a commit is one saved set of code changes.). A (A fixed chain of automatic steps, where each step hands its result to the next. A CI/CD pipeline builds, tests and releases every code change.) is a fixed list of automatic steps that every commit goes through. It builds the code into one package, tests it, and (A tree that stores words one letter per step, so words that start the same share a path.) it on a practice copy of the live system. Then it releases it to (The live system that real users reach, as opposed to a test or practice copy.), the servers that real users reach. Running these steps for every commit is called (Continuous integration and continuous delivery. CI builds and tests every saved change automatically. CD keeps every change that passes ready to release at any time. Releasing each one with no person in between is called continuous deployment.): continuous integration and continuous delivery. A release can reach all six servers at once, or one server at a time. It can also go to a second set of servers, or to one server with 10% of the traffic first. If the new version fails, a (Undoing a change to return to the last good state. A release rollback puts the previous version back. A transaction rollback cancels its writes.) puts the old version back.
Follow the checkout fix through the pipeline. The build step turns the code into one package, and every later step uses that same package. If any test fails, the pipeline stops there, and users keep the old checkout. If the tests pass, the release starts small, and the team watches error rates on the new servers. Only when those stay normal does the rest of the traffic move over.
The problem it solves
Without a pipeline, a release is a person copying files to servers by hand, often late at night. Steps get skipped, one server ends up with a different build, and nobody is sure how to go back. And if every server gets a faulty version together, every user hits the bug at once.
Why it matters
Many outages start with a change: new code, a new setting, a new table. An interviewer who asks "how would you roll this out?" wants two things. How do you limit the damage of a bad release, and how do you undo it?
A worked example
Say 1,000 people use an app each minute, and a new version fails half of its requests. Shipped to every server at once, about 500 people a minute see an error. Shipped as a (A release that gives the new version to a small share of the traffic first, such as 10%. If it fails there, few users are hurt and it is pulled back.) to 10% of the traffic, 100 people reach the new version and about 50 see an error. That is 10 times fewer, and an automatic check then pulls the version back.
Think of it like…
Think of a restaurant with a new recipe. The cook serves it to one table before it goes on every menu. If that table sends it back, only one table had a bad dinner.
Where this analogy stops working
Trying a change on a few before all is the useful part. A kitchen cannot take back a meal, while software can put the old version back. But a rollback restores only the code. Data that the faulty version wrote stays wrong until someone repairs it.
Try it
See it working
Also try: Load balancer · SLOs, error budgets & alerting
Mechanics
How it works
The pictures follow this page's example: a fix to the checkout button, made into build 412 and sent to six servers. The first shows the pipeline, the second three ways to ship, and the third a faulty release.
Every commit runs the pipeline
Pick a case to follow belowWith this case: The tests passed, and staging and then production ran the same build 412.
Commit, fixes checkout Commit fixes checkout Build and test, makes one package, NOW Build and test makes one package build 412 NOW Staging, practice copy Staging practice copy Production, runs build 411 Production runs build 411 - Commit — fixes checkout — healthy
- Build and test — makes one package — healthy — NOW — build 412
- Staging — practice copy — healthy
- Production — runs build 411 — healthy
- Package or traffic
Step 1 of 3Step 1 of 3 · Build and test
Done: A commit starts the pipeline
- What happens
- A developer saves a fix to the checkout button. Nobody presses a button to start the next steps.
- Why
- Every commit runs the same steps, so none gets skipped.
- What changes
- The pipeline builds it into one package: build 412.
- Next
- The tests pass, and staging runs build 412
Tests–not run yetStaging runsbuild 411Production runsbuild 411Step 1 of 3: Build and test. A commit starts the pipeline. A developer saves a fix to the checkout button. Nobody presses a button to start the next steps.
A commit starts the steps with no one pressing a button: build, test, package. A failing test stops the pipeline, and production keeps the old version. This first half is continuous integration (CI).
In the picture, the commit becomes build 412. If a test fails, the pipeline stops there and production keeps build 411. If the tests pass, (A practice copy of production, where a release is tried before real users get it.) runs build 412, and then production runs that same package.
Build once, ship the same package
Say build 412 passed the tests. Staging, the practice copy, runs build 412, and then production runs build 412, never a fresh rebuild. A rebuild could pull in newer outside code and behave differently from the one you tested. Keeping every passing build ready to release is continuous delivery (CD). Releasing each one with no person in between is continuous deployment.
Pick how to ship
Pick a case to follow belowWith this case: All at once was quick, but for a moment none of the 6 servers answered.
Load balancer, shares the traffic, NOW Load balancer shares the traffic NOW Server 1, serves users Server 1 serves users restarting Server 2, serves users Server 2 serves users restarting Server 3, serves users Server 3 serves users restarting Server 4, serves users Server 4 serves users restarting Server 5, serves users Server 5 serves users restarting Server 6, serves users Server 6 serves users restarting - Load balancer — shares the traffic — healthy — NOW
- Server 1 — serves users — healthy — restarting
- Server 2 — serves users — healthy — restarting
- Server 3 — serves users — healthy — restarting
- Server 4 — serves users — healthy — restarting
- Server 5 — serves users — healthy — restarting
- Server 6 — serves users — healthy — restarting
- Stop or failed request
- Answer
Step 1 of 2Step 1 of 2 · Load balancer
Watch: All 6 servers restart together
- What happens
- Each server stops version 1 and starts version 2 at the same moment.
- Why
- This is the fastest way to ship, and the simplest.
- What changes
- For a moment, no server answers, and users see errors.
- Next
- All 6 servers run version 2
Servers answering0 of 6Watch: nothing answersServers on version 20 of 6Step 1 of 2: Load balancer. All 6 servers restart together. Each server stops version 1 and starts version 2 at the same moment.
All at once: every server restarts together, so for a moment nothing serves. Rolling: one server at a time. (A release that starts a second full set of servers on the new version, then switches all traffic to it in one step. The old set stays ready for a fast switch back.): a second full set of servers starts, then all traffic switches in one step. Canary: one server gets about 10% of the traffic first.
In the picture, version 2 is good. All at once, every server restarts together, so for a moment none of the 6 answers. Rolling keeps at least 5 answering, but both versions run side by side for a while.
Blue-green starts 6 more servers, so 12 run for a while. One switch then moves all traffic, and blue stays ready for a fast rollback.
Watch, then widen or roll back
Pick a case to follow belowWith this case: As a canary at 10%, the faulty version failed about 1 request in 10 until it was rolled back.
Load balancer, shares the traffic Load balancer shares the traffic Server 1, serves users, NOW Server 1 serves users version 2 · 10% NOW Server 2, serves users Server 2 serves users version 1 Server 3, serves users Server 3 serves users version 1 Server 4, serves users Server 4 serves users version 1 Server 5, serves users Server 5 serves users version 1 Server 6, serves users Server 6 serves users version 1 - Load balancer — shares the traffic — healthy
- Server 1 — serves users — healthy — NOW — version 2 · 10%
- Server 2 — serves users — healthy — version 1
- Server 3 — serves users — healthy — version 1
- Server 4 — serves users — healthy — version 1
- Server 5 — serves users — healthy — version 1
- Server 6 — serves users — healthy — version 1
- Package or traffic
- Stop or failed request
- Answer
Step 1 of 3Step 1 of 3 · Server 1
Done: Server 1 runs version 2 and gets 10% of the traffic
- What happens
- The load balancer sends it 10% of requests, less than an even share of about 17%. The other 5 keep version 1.
- Why
- A small share limits how many users meet a bug.
- What changes
- Both versions now serve real users.
- Next
- Version 2 fails, and about 1 request in 10 fails
Servers on version 21 of 6Requests failing0%noneStep 1 of 3: Server 1. Server 1 runs version 2 and gets 10% of the traffic. The load balancer sends it 10% of requests, less than an even share of about 17%. The other 5 keep version 1.
What these pictures simplify. These pictures move in whole steps with stated shares of traffic. Real rollouts take minutes, and a canary is often watched for a set time before it widens. The deployments lab above runs every way of shipping with live traffic.
Compare the new version's error rate and (The time within which 99 out of 100 requests finish. The slowest 1% take longer.) (How long one request takes, from sending it to getting the answer.) with the old version's. With a canary at 10%, a faulty release reaches about 1 request in 10 until it is pulled. A rollback should be one command, and tried before you need it.
In the picture, version 2 fails every request it serves. As a canary, server 1 gets 10% of the traffic, so about 1 request in 10 fails until it is rolled back. All at once, every request fails until the rollback.
Feature flags: ship code switched off
A (A switch that the code reads while it runs. It turns a feature on or off, or shows it to a few users, without a new release.) is a switch that the code reads while it runs. Ship the new checkout code with its flag off, then turn it on for 1% of users. Turning a flag off takes seconds and needs no release.
Change the database first
During a rollout, old and new code run side by side on one database. Say version 2 needs a new column called discount. First add the column, which the old code ignores. Then ship the code that uses it. Remove an old column only when no running version reads it.
Use it when
- Every service that real users depend on: build the pipeline before the first release, not after the first outage.
- A canary or blue-green release for any change that is risky or hard to test, such as a new payment flow.
Skip it when
- A canary on a service with very little traffic: 10% of 2 requests a minute is too few to judge.
- Blue-green when a second full set of servers costs too much, or when the two versions cannot share one database.
- A feature flag left in the code for ever: each flag adds more paths to test, so remove it once the feature is fully on.
Check yourself
Judgement
Trade-offs and how it fails
What you give up
- Speed
- Shipping all at once is fastest and needs no extra servers, but every user gets a bad release together.
- Safety
- A canary or blue-green release limits the damage and is fast to undo. The price is more servers, more steps and a slower rollout.
Failure modes
- A rollout with no spare room: with one of six busy servers out, the other five are full and refuse requests.
- A canary that nobody checks: with no automatic check, the faulty version passes its wait and spreads to every server.
- A rollback that cannot work: version 2 already changed the data in a way that version 1 cannot read.
- Tests that fail at random: people learn to ignore a red pipeline, and then a real failure gets through.
In the real world
- Kubernetes replaces the copies of a service a few at a time by default, which is a rolling update.
- Netflix and Google built Kayenta, a tool that compares a canary's metrics with the old version's and scores the release.
- GitHub Actions, GitLab CI and Jenkins run a pipeline on every commit. Argo CD keeps the running servers in step with a description of them that is stored with the code.
- Amazon has described releasing a change to one server, then one data centre, then one part of the world, with a wait between each step.
Trade-offs to be ready to discuss: Rolling vs blue green · Canary speed vs safety
Check yourself
Interview
What interviewers look for
- After the design, add one line: "We'd ship behind a canary at 5 to 10% and roll back automatically if its error rate is higher."
- Say what you would watch during the rollout: the new version's error rate and p99 latency against the old version's.
- For a change to the data, say the order: add the new column, ship the code, remove the old column later.
Say it out loud: Why can a healthy rolling update still fail requests?
Expected depth by interview level
Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.
- JuniorUseful
- What a pipeline does, and why tests run before a release.
- MidUseful
- Rolling, blue-green and canary releases, and when to roll back.
- SeniorExpected
- A release plan for your design: the rollout, the rollback and the database change.
- StaffExpected
- Release safety across teams: which checks gate a release, how far a bad one spreads, and what it costs.
Practice
Apply it
Three harder questions
The first two use the idea on a new case. The last asks you to judge a design.
Apply it
Apply it
Judge a design
Go deeper
Sources and further reading
First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Engineering guideCanarying ReleasesGoogle SRE workbookSending a small share of traffic to a new version and comparing it with the old one.
- Engineering guideBlueGreenDeploymentMartin FowlerTwo production environments and a switch between them, so a rollback is one change.
- Official docsDeploymentsKubernetes documentationRolling updates, maxSurge and maxUnavailable, and rolling back to an earlier version.