Zero-downtime deployment

On this page 7

Zero-downtime deployment is a release practice in which a new version of an application replaces the old one without any interruption of service visible to users: no maintenance window, no failed requests and no lost sessions. In DevOps and in the Cloud subject more broadly, it is a core capability of continuous delivery, because teams that deploy many times per day cannot afford an outage for each release.

The approach rests on three ideas: running old and new versions side by side, shifting traffic gradually or atomically between them, and keeping every change backward compatible long enough for both versions to coexist. Strategies such as rolling, blue-green and canary deployment are concrete implementations of this goal.

How zero-downtime deployment keeps a service available

A zero-downtime deployment works by ensuring that healthy capacity always exceeds demand during the change. New instances are started, verified by health checks, and only then added to the load balancer, while old instances are removed only after they stop receiving traffic and finish their in-flight requests.

The final step, connection draining, is often overlooked. An instance about to stop first leaves the load balancer pool, then waits for a grace period, commonly 30 to 60 seconds, before the process exits. Without draining, users experience reset connections and failed requests even when enough capacity exists.

The following table summarizes the building blocks that a deployment pipeline must provide.

Building blockPurposeFailure if missing
Redundant instancesServe traffic while others are replacedCapacity gap during rollout
Readiness checksAdmit only instances able to serveRequests reach unready processes
Load balancer controlShift traffic between versionsNo way to steer users
Graceful shutdownFinish in-flight work before exitDropped requests and broken sessions
Automated rollbackRestore the previous version quicklyLong recovery after a bad release
Compatible schema changesLet both versions use the same dataErrors in the old or new version
Building blocks of a zero-downtime release

Deployment strategies that achieve zero downtime

Several strategies deliver zero downtime, and they differ mainly in cost, speed of rollback and exposure to risk. The choice depends on infrastructure budget, traffic volume and how much real-user validation a team wants before a full release.

StrategyMechanismExtra capacityRollback speed
Rolling deploymentReplace instances in small batchesLow, often one batchModerate; requires reverse rollout
Blue-green deploymentSwitch all traffic to an idle copyHigh, about doubleVery fast; switch back
Canary deploymentSend a small share of traffic firstLow to moderateFast; stop the canary
Feature flagsDeploy dark, enable code at runtimeNone beyond normalInstant; turn flag off
Shadow trafficMirror requests to the new versionModerateNot needed; users unaffected
Comparison of zero-downtime deployment strategies

In practice teams combine them. A common pattern is a rolling update with a canary phase: the first few percent of traffic reaches the new version, automated analysis compares error rates and latency, and the rollout continues only if the metrics stay within thresholds.

Database and state changes without downtime

The hardest part of zero-downtime deployment is usually data, not code. Because old and new versions run at the same time, every database change must work with both. The established technique is the expand and contract pattern, also called parallel change.

  1. Expand: add new columns or tables without removing old ones, and make new fields nullable or defaulted.
  2. Migrate: deploy code that writes to both structures and backfill existing data in small batches.
  3. Switch reads: release a version that reads only from the new structure.
  4. Contract: remove the old columns in a later release, once no running version depends on them.

The table below shows how typical schema changes are made safe.

ChangeUnsafe approachZero-downtime approach
Rename a columnRename in one migrationAdd new column, dual-write, drop old later
Add a required fieldAdd NOT NULL without defaultAdd nullable, backfill, then enforce
Remove a columnDrop together with code changeStop using it first, drop in next release
Large index buildBlocking index creationOnline or concurrent index creation
Safe handling of common schema changes

Long-lived connections, caches and message formats need the same discipline. Queue consumers must tolerate both message versions, and session data should live in a shared store rather than in instance memory, so users are not logged out when their instance is replaced.

Zero-downtime deployment on Kubernetes and cloud platforms

Cloud platforms provide most of the primitives, but correct configuration remains the team’s responsibility. On Kubernetes, a Deployment performs rolling updates controlled by the maxUnavailable and maxSurge settings; setting maxUnavailable to 0 guarantees that serving capacity never drops below the desired replica count.

  • Readiness probes must reflect true ability to serve, including warm caches and dependency connections.
  • A preStop hook with a short sleep gives load balancers time to remove the endpoint before shutdown.
  • PodDisruptionBudgets protect availability during node maintenance as well as during releases.
  • Managed load balancers need matching deregistration delays so that draining completes.

Tools built on GitOps, such as Argo CD with progressive delivery extensions, automate canary analysis and promote or abort releases from metrics rather than human judgment.

Limitations and common mistakes

Zero downtime is an engineering target, not an absolute guarantee. Some changes, such as major database engine upgrades or breaking protocol changes with external clients, may still require coordinated windows or a long migration path.

MistakeConsequencePrevention
Liveness probe used as readinessTraffic hits starting instancesSeparate readiness and liveness checks
No graceful shutdown handling5xx errors at every releaseHandle SIGTERM and drain connections
Breaking schema change with codeOld instances fail during rolloutApply expand and contract
Rollback never testedSlow recovery during an incidentRehearse rollback in staging
Monitoring only averagesCanary regressions go unnoticedCompare error rates and latency percentiles
Frequent mistakes and how to avoid them

Teams also underestimate cost and complexity: blue-green doubles infrastructure temporarily, and supporting two versions at once constrains how quickly APIs and data models can evolve.

In everyday language

Imagine a busy restaurant that renovates its kitchen without ever closing its doors. The staff set up a second cooking station, test it with a few dishes, and move the cooks over one by one. Guests keep getting their meals and never notice the change.

Zero-downtime deployment does the same for software. The new version is prepared next to the old one, checked carefully, and then given the work step by step. The key point is that users are never turned away while the update happens.

Seen in the real world

A payments company releases its transaction API around fifteen times per week. The service runs as 20 replicas on a Kubernetes cluster behind a cloud load balancer, with maxSurge at 25 percent and maxUnavailable at 0, and each Pod drains connections for 45 seconds before exiting.

Each release starts as a canary receiving 5 percent of traffic for ten minutes. An automated analysis compares the canary’s error rate and 99th percentile latency with the stable version. A recent release that added a currency field used the expand and contract pattern: the column was added as nullable one week, backfilled, and enforced the following week.

When one canary showed a rise in timeouts caused by a misconfigured connection pool, the pipeline aborted the rollout automatically within minutes. Customers saw no failed payments, and the team fixed and redeployed the change the same afternoon.