> ## Content Index
> Fetch the complete content index at: https://app.hostwolf.net/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# Zero-Downtime Deployment: Prerequisites Your App Must Meet First
- URL: https://app.hostwolf.net/blog/zero-downtime-deployment-prerequisites/
- Published: 2026-10-15T08:20:14.000Z
- Updated: 2026-10-15T08:20:18.000Z
- Description: Rolling and blue-green strategies fail if the application is not ready for them. This is an audit checklist of what your app itself must do before a deploy can be downtime-free — plus the honest cases where it cannot be.
- Author: Hostwolf
- Tags: Deploying, DevOps, Databases

Zero-downtime deployment fails at the application layer, not at the traffic switch. Rolling, blue-green and canary strategies all assume your app binds its listener before announcing readiness, shuts down gracefully on SIGTERM, drains keep-alive connections, keeps no state on local disk, and runs migrations that work with old and new code side by side. This is a checklist of those prerequisites, with honest notes on where downtime cannot be avoided.

**Jump to a prerequisite:**

1. [Bind before announcing readiness](#prerequisite-1-bind-before-announcing-readiness)
2. [Graceful shutdown on SIGTERM for zero-downtime deploys](#prerequisite-2-graceful-shutdown-on-sigterm-for-zero-downtime-deploys)
3. [Drain keep-alive connections, not just the listener](#prerequisite-3-drain-keep-alive-connections-not-just-the-listener)
4. [Stateless app requirements](#prerequisite-4-stateless-app-requirements--sessions-uploads-jobs)
5. [Backward-compatible migrations](#prerequisite-5-backward-compatible-migrations-expand-contract)
6. [The audit checklist](#the-audit-checklist) · [When downtime-free deploys are not possible](#when-downtime-free-deploys-are-not-possible)

## Introduction: The Strategy Is Not the Hard Part

Most articles on zero-downtime deployment compare rolling vs blue-green vs canary and stop at the traffic pattern. In practice the switch itself is the easy part. The errors come from the application's own behavior during startup and shutdown: connections refused because the port was not bound yet, 500s from dropped in-flight requests, sessions lost when an instance is removed, migrations that break the old version still serving traffic.

You can test every item in this article against your own app today, regardless of platform or hosting. None of it depends on a specific deploy tool. What matters is what the process does when it starts, when it receives a termination signal, and while two versions run at once.

Some honest limitations up front: apps with non-graceful protocols, single-node databases and breaking API changes cannot be deployed without downtime. We flag those cases rather than promising otherwise. No deploy strategy fixes a missing SIGTERM handler.

## Blue-Green vs Rolling vs Canary: What Each One Assumes About Your App

The three strategies differ in how traffic moves, but they share the same assumptions about your application. Definitions from the [HashiCorp Well-Architected Framework](https://developer.hashicorp.com/well-architected-framework/define-and-automate-processes/deploy/zero-downtime-deployments?ref=app.hostwolf.net):

| Strategy   | How it works                                                                                                                     | Rollback                 |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| Blue-green | Two identical environments; traffic switches all at once from old to new                                                         | Fastest: flip back       |
| Rolling    | Batched updates; HashiCorp, citing AWS guidance, recommends waves of at most 33% of the fleet with at least 66% capacity healthy | Re-roll previous version |
| Canary     | Incremental traffic to a subset of instances before full rollout                                                                 | Shift traffic back       |

What they all assume:

- More than one ready endpoint during the transition. [NGINX Gateway Fabric documents](https://docs.nginx.com/nginx-gateway-fabric/how-to/upgrade-apps-without-downtime/?ref=app.hostwolf.net) this explicitly: zero-downtime upgrades require more than one ready endpoint behind the gateway.
- Backward-compatible API and schema during the window when old and new versions serve the same routes. [Cloud Foundry's rolling-deploy docs](https://docs.cloudfoundry.org/devguide/deploy-apps/rolling-deploy.html?ref=app.hostwolf.net) state this as a requirement, not a suggestion.
- Sessions and uploads that survive an instance swap. Anything stored on one instance's local filesystem or memory is lost when that instance goes away.

One real constraint worth naming: blue-green requires two nearly identical environments plus headroom. On a single dedicated server, that means sizing for roughly double the workload during the switch. For most apps on one box, a rolling deploy with a small surge is the practical choice.

## Prerequisite 1: Bind Before Announcing Readiness

If your app reports healthy before its listener is bound, the router sends traffic to a port that does not exist yet and clients see connection refused. The correct order is: start, bind the listener, then flip the readiness or health endpoint to serving. Never the other way around.

The [Kubernetes probe docs](https://kubernetes.io/docs/concepts/configuration/liveness-readiness-startup-probes/?ref=app.hostwolf.net) make the distinction concrete: readiness probes gate traffic, and a failed readiness probe removes the Pod's IP from Service endpoints without restarting the container. Liveness and startup probes, by contrast, kill the container on failure and apply the restart policy. The defaults are periodSeconds 10, timeoutSeconds 1, failureThreshold 3 and initialDelaySeconds 0\. Use those as a calibration baseline even if you are not on Kubernetes: if your load balancer checks health every 3 seconds with a 1-second timeout, your readiness flip must propagate within that window.

One warning from [AWS EKS best practices](https://docs.aws.amazon.com/eks/latest/best-practices/application.html?ref=app.hostwolf.net): readiness should reflect only in-process temporary unavailability, not external dependencies. If your readiness check pings the shared database, one DB blip marks every replica not Ready at once and traffic stops entirely. Check the database with a separate liveness-style check if you must, and keep readiness scoped to "can this process serve requests".

If a load balancer sits in front, align its health-check path and interval with the app's readiness endpoint so the instance is removed from the pool before the socket closes. An [AWS containers blog case study](https://aws.amazon.com/blogs/containers/how-to-rapidly-scale-your-application-with-alb-on-eks-without-losing-traffic/?ref=app.hostwolf.net) aligned the ALB health check with the pod's readiness probe (3-second interval, shared endpoint) and reduced 504s during scale-down from an average of 340 per event to zero. That is AWS's measurement on their setup, not a guarantee for yours, but it shows the size of the effect.

## Prerequisite 2: Graceful Shutdown on SIGTERM for Zero-Downtime Deploys

Most platforms share the same termination contract: the platform sends SIGTERM, your app must stop listening, finish in-flight requests, close downstream connections and exit. The window is short. [Kubernetes defaults](https://kubernetes.io/docs/concepts/configuration/liveness-readiness-startup-probes/?ref=app.hostwolf.net) to a 30-second terminationGracePeriodSeconds, [Cloud Foundry waits 10 seconds](https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html?ref=app.hostwolf.net) before killing the app, and [Render](https://render.com/articles/how-render-handles-zero-downtime-deploys?ref=app.hostwolf.net) keeps the old instance running 60 seconds after traffic switches, then sends SIGTERM. From SIGTERM, the default shutdown delay is 30 seconds before SIGKILL, extendable to 300 seconds via `maxShutdownDelaySeconds`.

[AWS prescriptive guidance](https://docs.aws.amazon.com/prescriptive-guidance/latest/ha-resiliency-amazon-eks-apps/lifecycle-hooks.html?ref=app.hostwolf.net) documents the two classic failure modes. First, the app drops in-flight requests when it exits, so clients see 500s. Second, it finishes its work but keeps accepting new connections, because routing-table and endpoint propagation lags behind endpoint removal. The fixes: handle SIGTERM explicitly, optionally add a short delay before shutting down (AWS's example uses a 20-second preStop sleep), and size the grace period to cover your cleanup.

Per-stack patterns, briefly. PHP is the one to verify by hand rather than assume: how termination signals reach your application code under php-fpm depends on your process-manager and web-server configuration, so kill a running instance and confirm your handler behaves before you rely on it. For the full PHP picture, including queues and scheduled tasks, see [our Laravel deployment runbook](https://app.hostwolf.net/blog/deploy-laravel-app-to-vps/).

**Node.js / PM2.** [PM2 sends SIGINT on stop](https://pm2.io/docs/runtime/best-practices/graceful-shutdown/?ref=app.hostwolf.net), not SIGTERM. Intercept it, stop accepting requests, wait for in-flight ones to finish, then close pools and exit:

```js
let open = 0;
server.on('request', (req, res) => {
  open++;
  res.on('close', () => open--);
});

process.on('SIGINT', async () => {
  server.close();          // stop accepting; in-flight requests still resolve
  const wait = () => (open > 0 ? setTimeout(wait, 100) : null);
  await new Promise(wait); // wait for in-flight requests to drain
  await dbPool.end();      // only now close pools
  await queue.close();
  process.exit(0);
});

```

**Python / Uvicorn.** [Uvicorn handles SIGINT and SIGTERM natively](https://uvicorn.run/deployment/?ref=app.hostwolf.net): it stops accepting connections, waits for in-flight requests up to `timeout_graceful_shutdown`, then runs lifespan shutdown. If you run it under Gunicorn, use the `uvicorn-worker` package; `uvicorn.workers` is deprecated.

**Go.** Since Go 1.8, `http.Server.Shutdown()` provides graceful shutdown. The [Gin docs](https://gin-gonic.com/en/docs/server-config/graceful-restart-or-stop/?ref=app.hostwolf.net) show the pattern: trap SIGINT/SIGTERM, call Shutdown with a context. Their 5-second context is illustrative, not a recommendation. Gin also notes graceful shutdown enables zero-downtime deployments when combined with a load balancer, which is exactly the dependency this article describes.

**Workers, not just web processes.** The [twelve-factor disposability rule](https://12factor.net/disposability?ref=app.hostwolf.net) applies to queue workers: on SIGTERM, a worker must return the current job to the queue, startup should take seconds, and jobs must be reentrant and idempotent. [Porter documents](https://docs.porter.run/applications/configure/zero-downtime-deployments?ref=app.hostwolf.net) a shutdown-marker-file pattern for workers: on SIGTERM, write a marker file, and have the worker's health check test for it so the platform removes the worker from rotation.

## Prerequisite 3: Drain Keep-Alive Connections, Not Just the Listener

The step most often absent from shutdown checklists: after SIGTERM, new requests can still arrive on already-accepted keep-alive connections even though the listener is closed. Closing the listener is not enough. Draining means closing or marking keep-alive sockets, responding with `Connection: close` or a 503 during the drain window, and force-terminating at a deadline. The [bex.co shutdown reference](https://bex.co/docs/platform/http-shutdown?ref=app.hostwolf.net) describes exactly this, including a `SHUTDOWN_DEADLINE_MS` force-terminate.

Draining is also protocol-dependent. The [ACM paper on server upgrade systems](https://dl.acm.org/doi/pdf/10.1145/3387514.3405885?ref=app.hostwolf.net) found that graceful draining requires protocol support (HTTP/2 has GOAWAY for this), does not cover a significant subset of connections (HTTP/1.1 keep-alive nuances, MQTT), and cannot gracefully conclude long-lived connections at all. WebSockets are the practical case: plan for disconnect-and-reconnect with client-side retry, because draining will not save those sessions.

A practical drain sequence, following the [Connectum shutdown model](https://connectum.dev/en/guide/server/graceful-shutdown?ref=app.hostwolf.net):

1. Flip the health endpoint to not-serving first, so the router removes you from rotation.
2. Close transports (HTTP/2: send GOAWAY).
3. Race in-flight requests against a timeout.
4. Force-close whatever remains.

And the grace-period math that ties it together: `terminationGracePeriodSeconds >= preStop delay + drain timeout + max cleanup duration + margin`. Kubernetes runs the preStop hook before SIGTERM, so a preStop sleep counts against the same budget. Size it accordingly, not by guesswork.

## Prerequisite 4: Stateless App Requirements — Sessions, Uploads, Jobs

During a rolling or blue-green switch, old and new instances serve the same routes simultaneously, and any instance may be removed mid-session. Statelessness is a hard prerequisite for any zero-downtime strategy, not an architecture preference.

**Sessions.** Externalize session state to a shared store such as Redis or your database. The [AKS zero-downtime migration guide](https://learn.microsoft.com/en-us/azure/aks/zero-downtime-migration/?ref=app.hostwolf.net) warns that sticky-session apps risk affinity-related outages during traffic shifts, and shows externalizing session state to a cache as the fix. In-memory session stores break the moment a second instance exists.

**Uploads.** Local-disk uploads are a documented gap: an instance removed during a rolling deploy loses anything written to its local filesystem. Store uploads in object storage or a shared volume before you attempt a rolling deploy, not after the first failed one.

**Queue workers and scheduled tasks.** Jobs must be idempotent and reentrant. A long-running job needs checkpointing or requeue behavior so that a SIGTERM in the middle of a deploy neither loses the work nor duplicates its side effects. This is the twelve-factor disposability requirement applied to your background processing, and it is the one teams discover the hard way when a nightly report runs twice.

## Prerequisite 5: Backward-Compatible Migrations (Expand-Contract)

The hard rule, stated plainly in [Cloud Foundry's rolling-deploy docs](https://docs.cloudfoundry.org/devguide/deploy-apps/rolling-deploy.html?ref=app.hostwolf.net): deployment tooling does not handle database migrations. Old and new versions run side by side, so every schema change must work with both. That rules out most migrations written as if they ran alone.

The pattern that works is expand/migrate/contract, formalized in the [OpenStack Glance database migration docs](https://docs.openstack.org/glance/latest/contributor/database%5Fmigrations.html?ref=app.hostwolf.net): expand is additive-only, migrate is data-only with no schema change, and contract removes the old shape. Contract migrations depend on their expand counterparts and ship in a later release.

A concrete column-move recipe, from the [Openverse zero-downtime database management docs](https://docs.openverse.org/general/zero%5Fdowntime%5Fdatabase%5Fmanagement.html?ref=app.hostwolf.net):

1. Add the new column as nullable.
2. Deploy code that dual-writes to both columns and reads the new with fallback to the old.
3. Run a backfill until the query counting null values in the new column returns zero rows.
4. Deploy removal of the old column.

The [MinimumCD expand-and-contract guide](https://beyond.minimumcd.org/docs/foundations/evolutionary-coding/expand-and-contract/?ref=app.hostwolf.net) documents the failure modes: skipping the backfill before cutover, dropping the old column while any code still references it, and collapsing the phases into one deployment. Four small reversible deployments beat one big-bang change.

Lint your migrations in CI. A useful gate, modeled on the [OpenCTEM migration policy](https://docs.openctem.io/developers/migrations/?ref=app.hostwolf.net), fails any pull request containing `DROP TABLE`, `DROP COLUMN`, `ALTER COLUMN TYPE`, `RENAME`, `SET NOT NULL`, a `NOT NULL` column added without a default, or `TRUNCATE`. For PostgreSQL, set a `lock_timeout` on migrations and create indexes with `CONCURRENTLY`; tools like Squawk catch these classes of mistakes. Before any aggressive migration, take a fresh backup with a retention policy you actually configured, and verify you can restore from it.

Tooling notes: the [Alembic zero-downtime pattern](https://that.guru/blog/zero-downtime-upgrades-with-alembic-and-sqlalchemy/?ref=app.hostwolf.net) splits the change into three separate migration files, which means you can no longer use `alembic upgrade head`. Plan for that in your release tooling. And one honest exception: some changes, such as conflicting uniqueness constraints, genuinely need a maintenance window. That is the exception, not the default.

Single-node databases deserve their own caveat: there is no zero-downtime recipe short of replicate-and-promote or dual-write, and both carry high operational complexity. If your database is a single node on your app server, accept the window or plan the replication work deliberately.

## The Audit Checklist

Run this against your app today. Each item is pass or fail.

- Listener is bound before the readiness endpoint flips to serving
- A SIGTERM handler exists and is actually tested (kill a running instance and watch)
- Readiness endpoint reflects in-process state only, not the shared database
- Keep-alive draining is implemented, with `Connection: close` or 503 responses and a force-close deadline
- Sessions live in a shared store, not process memory
- Uploads go to object storage or shared volume, not local disk
- Workers are idempotent, signal-aware, and return current jobs to the queue
- Migrations pass a destructive-operation lint gate
- Grace period sized with the drain math: preStop + drain + cleanup + margin

Suggested test method: deploy while a load generator runs against the app, even a simple curl loop, and count failed requests. A 502 or 500 spike points at whichever prerequisite is missing: connection refused means readiness flipped too early, 500s mean in-flight requests were dropped, auth errors or lost carts mean statefulness. This is a testing approach, not a benchmark.

## When Downtime-Free Deploys Are Not Possible

Some apps cannot be deployed without downtime, and pretending otherwise leads to surprise outages. The honest cases:

- Breaking API or wire-format changes without versioning. If old and new clients must never coexist, you have a window.
- Single-node database engine upgrades. No recipe short of replicate-and-promote or dual-write, both operationally expensive.
- Apps where you cannot verify your shutdown handler actually runs, including legacy runtimes and PHP setups where the process manager owns process lifetime. Test before you trust it.
- Long-lived connection protocols without drain support. WebSockets need client reconnect logic; draining cannot conclude them gracefully.
- Schema changes that require a maintenance window, like conflicting uniqueness constraints.

The practical response is to detect these early, schedule a maintenance window deliberately, and shorten it with rehearsed deploys. A rehearsed five-minute window beats an unplanned hour-long one, and it beats pretending a deploy strategy will fix a protocol problem.

## The Audit Is the Deploy Plan

Zero-downtime deployment is earned at the application layer, and the checklist above is the audit that earns it. If you would rather not hand-assemble the deployment plumbing on a box, Hostwolf Apps builds and runs apps from a GitHub repo on a dedicated server, but the application-side prerequisites are yours to implement either way.

## Frequently asked questions

### What is the difference between a liveness and a readiness probe?

Readiness gates traffic: when it fails, the instance is removed from the pool of endpoints but keeps running. Liveness (and startup) probes restart the container when they fail. Use readiness for deploys and traffic control, liveness only for genuinely hung processes.

### How long does my app have to shut down before being force-killed?

It depends on the platform: Kubernetes defaults to 30 seconds (terminationGracePeriodSeconds), Cloud Foundry waits 10, Render allows up to 300 seconds via maxShutdownDelaySeconds. Check your platform's grace period and make sure your drain time fits inside it.

### Why do requests still arrive after my app receives SIGTERM?

Routing removal propagates with a small delay, and keep-alive connections already accepted continue to deliver requests. Handle this by failing your readiness or health check first, closing keep-alive sockets or responding with Connection: close, and draining in-flight requests before exit.

### How do I rename or backfill a database column without downtime?

Use expand-contract: add the new column as nullable, deploy code that writes to both columns and reads the new with fallback to the old, backfill until no rows are null, then deploy the removal of the old column in a later release. Never rename or drop in the same deploy that ships the new code.

### What happens to queue workers during a zero-downtime deploy?

They receive the same termination signal. On SIGTERM a worker should stop taking new jobs, return the current job to the queue (or finish it if it is short), and exit. Jobs must be idempotent so a re-delivery after an interrupted deploy does not cause duplicate side effects.