SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • Deployment Strategies Overview
  • CI/CD Pipelines
  • Rolling Deployments
  • Blue-Green Deployments
  • Canary Releases
  • Feature Flags
  • A/B Testing Infrastructure
  • Schema Migrations
  • Rollbacks and Immutable Infrastructure
  • Multi-Region and Active-Active
  • Infrastructure as Code (Terraform)
  • Auto-Scaling Policies
  • Zero-Downtime Deployment
  • Chaos Engineering
  • Shadow Traffic and Dark Launches
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Deployment Patterns

Zero-Downtime Deployment

Ship new code with no failed requests: draining, health gates and changes that old and new can share.

⏱ 12 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Zero-downtime deployment means users do not notice a release: no error pages, no dropped requests, no maintenance window. It is not one technique. It is a set of habits that work together.

  • Many instances behind a load balancer, so some are always serving.
  • Readiness checks and draining: never send traffic to a server that is not ready, and never kill one that is mid-request.
  • Compatible changes: old and new versions must be able to run side by side, including against the same database.

02Concept: What is it?

Rolling, blue-green and canary are mechanisms for moving traffic from the old version to the new. Each of those has its own topic. Zero downtime is the outcome, and the mechanism alone does not guarantee it. A rolling update that kills servers mid-request, or sends traffic to a server still starting, still drops requests. A blue-green switch that changes the database in a breaking way still breaks the old version.

There are three things that must be true, whatever mechanism you pick:

NeedWhat it meansIf missing
Spare capacityAt least two instances, and room to lose one during the rolloutA single instance restart is an outage
Safe handoverReady before traffic in, finished before traffic outErrors during start and stop
CompatibilityOld and new code work with the same data and APIs at the same timeFailures from mixed versions, and rollback becomes impossible
The safe life of one instance during a release
🚰Stop new requestsremove from the load balancer
→↓wait
⏳Drainfinish in-flight requests
→↓then
🆕Start new versionwarm up
→↓readiness passes
✅Receive traffic
Out of rotation, drained, replaced, checked, back in.
🧠Rollout safety is mostly about two seconds
The danger is not the new version, it is the moments around it: the instant before a server dies and the instant before a new one is truly ready.

03Real-Life Example

🍵Changing a Shift at a Busy Shop
A shop is open all day. Staff change shifts without closing. The outgoing cashier finishes the customer in front of them (draining) before leaving. The new cashier puts on the apron and logs into the till (readiness) before the line is sent to them. And the till's menu must work for both cashiers, because for a few minutes they are both working (compatibility). If anyone skips a step, a customer is left at an empty counter.
Shift change
Zero-downtime deploy
The shop stays open
The service keeps serving
Cashier finishes the current customer
Connection draining and graceful shutdown
New cashier logs into the till first
Readiness check before traffic
Both cashiers use the same till menu
Old and new share one database and API contract
Only one cashier changes at a time
Rolling update with a limit on unavailable instances
Staff needed on the floor all day
Spare capacity during the rollout
Swap back if the new cashier struggles
Fast rollback

04Why Do We Need It?

🕐Deploy any time
No waiting for 3 am. Teams can release small changes during the day.
😌No lost requests
Users do not see error pages, and payments do not fail halfway.
🔁Smaller, safer releases
When deploys are painless, people ship more often and in smaller steps.
📈Meets availability goals
Planned downtime counts against your SLO. This removes it.
🧯Easy rollback
Compatible changes mean you can go back without a data fix.
🌍Global users
There is no good hour for maintenance when users are in every time zone.
Zero-downtime is not luck or a tool. It is the result of three small disciplines: capacity, handover and compatibility.

05Where Do We Use It?

🌐Web and API services
The standard case: stateless instances behind a load balancer.
☸️Kubernetes
Rolling updates with readiness probes, maxUnavailable, and a termination grace period.
🛒Checkout and payments
Any path where a dropped request costs money.
🗄️Database changes
Expand and contract migrations let the schema change while the app runs.
🔌WebSocket and streaming servers
Long-lived connections need a plan to move clients without a storm of reconnects.
📬Queue consumers
Finish or hand back the current message before stopping.

06Types / Parts / How It Works

The building blocks

BlockWhat it doesDetail
Readiness checkTells the load balancer when a new instance can take trafficCheck the app and its needs (database, cache), not just that the process is alive
Connection drainingStop new requests to an instance, let current ones finishSet a timeout longer than your slowest normal request
Graceful shutdownOn a stop signal (SIGTERM), stop accepting work, finish, then exitThe app must handle the signal. Many do not by default
Rolling limitsControl how many instances change at onceKeep enough capacity serving. Surge a little before removing
Backward-compatible changesNew code works with old data and old clientsNeeded because two versions run at once
Expand and contractAdd first, switch the code, remove lastHow to change a database without breaking the old version
Warm-upFill caches and connections before taking full loadA cold instance can be slow enough to look broken

Expand and contract, in three releases

Renaming a column without downtime
1. Expand
➕Add new columnold code ignores it
✍️Write to bothand backfill old rows
2. Switch
👀Read the new columnold column still kept in step
3. Contract
🧹Stop writing the old onethen drop it in a later release
Never rename in one step. The old version would break the moment the column changes.

Which mechanism, and what it still needs

MechanismHow traffic movesIt still needs
RollingReplace instances a few at a timeDraining, readiness, compatible versions
Blue-greenSwitch all traffic between two full copiesCompatible database, warm green copy, session handling
CanaryShift a small slice, then growMetrics to judge the slice, compatible versions
Expand Switch Contract
VisualizerRoll a release across the fleet and watch for dropped requestsStep through the rollout. Then turn off the readiness check, turn off draining, or mark the schema change as breaking, and see exactly which step drops requests and why.
Step 1 of 13: Start: all instances run the old version
🖥️
Instance 1
v1
🖥️
Instance 2
v1
🖥️
Instance 3
v1
🖥️
Instance 4
v1
Failed so far
0
requests
Failed in the whole rollout
0
of about 1300
Steps that hurt
0
Start: all instances run the old version.

Illustrative model: about 100 requests per step, spread evenly. Real numbers depend on traffic, request length and how many instances are taken out at once.

07How to Use It / Steps / Implementation

A zero-downtime checklist

  1. 1
    Run at least two instances
    Across zones if you can. A single instance cannot be replaced without a gap.
  2. 2
    Add a real readiness check
    It should pass only when the app can do useful work: config loaded, dependencies reachable, caches ready.
  3. 3
    Handle the stop signal
    On SIGTERM stop taking new work, finish the current requests, close connections, then exit.
  4. 4
    Give shutdown enough time
    Set the grace period longer than your slowest request. Add a short pause so the load balancer notices the instance is leaving.
  5. 5
    Limit how many change at once
    Allow a small surge of extra instances, and a small number unavailable.
  6. 6
    Make every change compatible
    Use expand and contract for databases. Add fields before using them. Keep old API behaviour until clients have moved.
  7. 7
    Plan for long-lived connections
    Tell clients to reconnect, and spread reconnects over time so the new instances are not swamped.
  8. 8
    Watch it and keep a way back
    Check error rate and latency during the rollout, and stop or roll back automatically if they worsen.
💡Test it, do not assume it
Run a load test while deploying to staging. Count failed requests during the rollout. If it is not zero, you have found the missing step.
⚠️Rollback must be compatible too
If version 2 wrote data that version 1 cannot read, you cannot go back. Keep changes backward compatible until you are sure you will not need to roll back.

08Key Terms to Know

TermMeaning in easy words
Zero-downtime deploymentReleasing a new version without users noticing
Readiness checkA test that says an instance can take traffic
Liveness checkA test that says an instance is running, not stuck
Connection drainingLetting in-flight requests finish before an instance leaves
Graceful shutdownFinishing work cleanly when told to stop
SIGTERMThe stop signal sent to a process before it is killed
SurgeExtra instances added during a rollout to keep capacity
Backward compatibleNew code works with data and clients made for the old code
Expand and contractAdd the new thing, switch to it, then remove the old thing
Warm-upGetting caches and connections ready before full load
Grace periodHow long a process gets to shut down before being killed
RollbackGoing back to the previous version

09Pros, Cons and Trade-offs

✅ Pros
  • Users never see a release
  • Releases can happen at any time
  • Smaller, more frequent changes
  • Failures during deploys drop sharply
  • Meets strict availability goals
⚠️ Cons
  • Needs spare capacity during the rollout
  • Changes take more steps (expand and contract)
  • Old and new versions must coexist, which is harder to test
  • Needs good health checks and shutdown handling
  • Long-lived connections need extra care

Trade-offs

ChoiceWe gainWe lose
Surge during rolloutFull capacity throughoutBrief extra cost
Long drain timeoutFewer cut requestsSlower rollouts
Expand and contractSafe database changesSeveral releases for one change
Blue-green switchFast cutover and rollbackDouble the servers for a while
Strict readiness checkNo traffic to a half-ready serverA broken dependency can block the whole rollout

10Common Problems and Mistakes

Common mistakes

  1. A readiness check that always says yes. The load balancer sends traffic to a server still starting.
  2. Killing instead of draining. In-flight requests, uploads and payments are cut off.
  3. An app that ignores SIGTERM. It is killed at the end of the grace period, mid-request.
  4. A breaking schema change in one step. Old instances still running fail the moment the database changes.
  5. Removing a field clients still use. Old mobile apps keep calling for weeks.
  6. No spare capacity. Taking one instance out overloads the rest.
  7. Forgetting the load balancer delay. It keeps sending traffic for a few seconds after an instance starts shutting down.

Things to watch

🔌WebSockets
Closing all connections at once makes every client reconnect together. Close in batches.
🧊Cold caches
A fresh instance can be slow. Warm it before it takes full load.
🍪Sessions
If sessions live in memory, each replaced instance logs users out. Use a shared store.
⏱️Long requests
A job longer than the grace period will be cut. Move long work to a queue.

11Real-World Examples

☸️Kubernetes rolling updates
Readiness probes, maxSurge and maxUnavailable, and a termination grace period are built in.
☁️Cloud load balancers
Connection draining (also called deregistration delay) is a setting on target groups.
🐘Postgres and MySQL changes
Teams use expand and contract, and tools that change large tables without long locks.
🌀Nginx and HAProxy
Reload configuration gracefully so existing connections finish on the old workers.
📱Mobile APIs
Old app versions stay in use for months, so APIs keep old behaviour a long time.
🛍️Large retailers
Deploy many times a day, with automated checks that stop or roll back a bad rollout.
Mini case: a deploy that drops requests
🔪Killed mid-requestno draining
→↓then
🥶New instance gets traffic coldno readiness
→↓then
💥Old instances read new schemabreaking migration
Three small gaps each lose a few requests. Together they are visible.

12Related Topics to Read Next

Rolling Deployments→

Replace instances a few at a time. The most common mechanism.

Blue-Green Deployments→

Switch between two full copies of production.

Canary Releases→

Send a small slice of users to the new version first.

Schema Migrations→

How to change a live database safely.

Health Checks→

The readiness checks that gate traffic.

Deployment Strategies Overview→

A map of all the ways to ship.

Rollbacks and Immutable Infrastructure→

Going back quickly when a release is bad.

Feature Flags→

Ship code dark, then turn it on separately.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔Outcome, not a tool: rolling, blue-green and canary are only mechanisms.
  • ✔Capacity: two or more instances, room to lose one.
  • ✔In: readiness check before any traffic.
  • ✔Out: drain and handle SIGTERM before stopping.
  • ✔Data: expand and contract, never a breaking change in one step.
  • ✔APIs: old and new must work together.
  • ✔Special cases: WebSockets, sessions, cold caches, long jobs.
  • ✔One line: “Ready before in, finished before out, compatible all the way through.”
← Previous
Auto-Scaling Policies
Next →
Chaos Engineering