Four guarantees between a deploy and serving traffic
Digest-truthful deploys
A deploy is pinned to the image digest it resolved, so a moved tag cannot change what serves. Rollbacks deploy the recorded pinned reference.
Stale-deploy guard
Automated deploys carry a per-app sequence number and commit order, so an older build still in flight cannot overwrite a newer one. Manual deploys and rollbacks are never rejected.
Freeze windows
Block automated deploys on a cron schedule, for example every Friday evening, and release them afterwards.
Instant rollback window
The previous release is held briefly after cutover, and prior images stay pinned so garbage collection cannot remove a rollback target.
Three strategies
Blue-green, rolling or recreate, all gated on readiness and liveness probes.
A reason for every state
The reconciler records a status condition with a reason after each pass, so a stuck deploy explains itself.
The order of a cutover
Deploys, restarts and rollbacks follow the same order, and every step waits for the one before it:- The new release starts and passes its readiness probe (and the stable window, when one is set).
- The route moves to it. Until then the release that was serving keeps every request.
- The previous release keeps answering in-flight requests for the drain timeout (
APP_DEPLOY_DRAIN_TIMEOUT), then stays held for a rollback (APP_DEPLOY_PREVIOUS_RELEASE_HOLD) and is stopped after that.
APP_INGRESS_RETRY_WINDOW, so a client with a shorter timeout sees a failed request.
What stays running after a cutover
Two different things can leave an older release on disk, and neither is a standing replica.- The held previous release. Exactly one: the newest release before the current one keeps running for
APP_DEPLOY_PREVIOUS_RELEASE_HOLD(at least the drain timeout, and the watch window when auto-rollback is on), then it is stopped and removed. Older releases are removed at cutover. - Deploy URL copies. Opening an old deploy at its own URL uses a one-replica copy of that deploy’s pinned image. Copies are created asleep, so nothing runs until the URL is visited, and they sleep again after
APP_DEPLOY_URL_IDLE_MINUTES. At mostAPP_DEPLOY_URL_MAX_COPIES(default1) exist per app, within the newestAPP_DEPLOY_URL_KEEPdeploys (default3,0turns the feature off). Copies are removed when the app is deleted or falls out of the window.
APP_DEPLOY_URL_MIN_FREE_MEMORY_MB available (default 1024), or when the app’s memory limit is above APP_DEPLOY_URL_MAX_MEMORY_PERCENT percent of host RAM (default 25); 0 turns either check off.
A stopped app stays stopped: no revive path starts an older release while the app is suspended.
A rollback to a release that is still held reuses it only when its container is the same one that served before. A rollback that has to start a fresh container goes through the full readiness gate, so traffic stays on the current release until the restored one is ready. That takes the readiness time plus the stable window.
Rollbacks follow the same three steps:
- A held container that was stopped and is started again for the rollback counts as a new process. It passes readiness before it takes traffic, even though the container itself is older than the rollback.
- When the restored release gets a new container (for example a rollback by digest), a held container that runs the same image serves while the new one warms up.
- When the rollback lands on a held release that is still running, the release it replaces keeps answering in-flight requests for the drain timeout, as after a deploy.
Frequently asked questions
What does zero downtime require from my app?
What does zero downtime require from my app?
A readiness endpoint that returns success only when the app can serve. Cutover waits for it.
What if the new version never becomes ready?
What if the new version never becomes ready?
Traffic stays on the current release and the deploy is reported as failed, with logs and a reason.
Can a stale build overwrite a newer one?
Can a stale build overwrite a newer one?
Not for automated deploys: the stale-deploy guard skips them. Manual deploys and explicit rollbacks always run.
Does it work on one server?
Does it work on one server?
Yes. The same cutover logic runs on a single node.
Ship without holding your breath
Read the deploy safety guide or try it on a spare server. Read deploy safety | View on GitHubProbe a redeploy under load
scripts/zero-downtime-load/run.sh checks the cutover order above with real traffic. It starts a throwaway dev-mode control plane, creates one app from traefik/whoami, sends requests to it at a steady rate through the HTTPS ingress, and redeploys the app while the requests continue. It then reports how many requests failed.
It needs a checkout of this repository (it builds ./cmd/levelrail from the repo root), Go, a Docker daemon reachable through the current Docker context, and curl, awk and sort. It uses its own ports and never touches the dev app on port 8080. Dev mode and the fixed dev token are for local use only.
The app starts on tag
v1.10.3. Redeploy 1 uses v1.10.2, redeploy 2 uses v1.10.1 and redeploy 3 uses v1.10.0.
Environment variables:
The script removes the app and any containers named
zdl- when it exits.
Reading the output
The script prints these lines, in order:create: <status>, the HTTP status of the create call.- For each redeploy,
deploy N: <status>and then eitherdeploy N: new release answeringordeploy N: NEVER CUT OVER. The second means the route did not move to the new release within the wait limit of 360 polls, about three minutes. requests N, the number of requests sent, failed ones included.failures N, the number of requests that did not return a 2xx status. A request that got no response is counted with status000.latency p50 ... p95 ... p99 ..., measured over 2xx responses only.longest gap between 2xx, in seconds. At the default rate, requests are 0.05 s apart, so a gap of a second or more means no 2xx response arrived for that long.- Only when there are failures:
failing window, the first and last failing timestamps as epoch seconds, and a count per status code. control plane log:, the path to the server log.
0 when every request returned 2xx and every redeploy cut over. It is 1 when any request failed, when any redeploy printed NEVER CUT OVER, when the build fails, or when the app never answers. -d defaults to 3, the number of redeploys the script has image tags for, and values above that are refused.
A deploy that says NEVER CUT OVER fails the run even with zero failed requests, because the requests only reached the old release.
Recorded result
One recorded run exists. Two of three redeploys cut over without failed requests. The third is unexplained and still open. Everything else ispending run:
- Rates other than 20 requests per second.
- Settle times other than 8 seconds.
- Images other than
traefik/whoami. - Rollbacks while requests are running.
- A real VPS, a public domain or more than one node.