Documentation

Zero-Downtime Cutover

ready

How NextDeploy achieves true zero-downtime releases on Linux VPS hosts using ephemeral port allocation, dual-stage TCP/HTTP health probes, atomic POSIX renameat() symlink swaps, and graceful connection draining.

Source reference: docs/internals/atomic-cutover.md, daemon/


Release Isolation & Ephemeral Port Allocation

Every nextdeploy ship builds into a brand-new immutable release directory:

/opt/nextdeploy/apps/my-app/releases/2026-11-23_14-20-00/
  1. nextdeployd inspects active listening ports and assigns an idle internal loopback port (e.g. 127.0.0.1:3002 while the active release runs on :3001).
  2. The incoming release boots inside its own systemd scope under its configured cgroup v2 memory limit.
  3. A temporary symlink current.tmp is created pointing at the new release directory.

Dual-Stage Health Probing

No live traffic shifts until both stages pass:

Stage 1: TCP Port Probe

Verifies the Node.js HTTP listener is bound and accepting connections — catching startup crashes, missing env vars, or syntax errors immediately.

Stage 2: HTTP Semantic Probe

Issues HTTP GET requests to deployment.healthcheck.path (default /api/health):

GET /api/health HTTP/1.1
Host: 127.0.0.1:3002

The deploy advances only when the endpoint returns 200 OK within timeout (default 5s) across retries attempts.


Atomic Symlink Swap & Connection Draining

Rendering diagram…

The 4-Step Cutover Protocol:

  1. nextdeployd validates and reloads Caddy's fragment (/etc/caddy/nextdeploy.d/<app>.caddy) pointing at the healthy candidate port.
  2. Executes an atomic POSIX os.Rename("current.tmp", "current") swap pointing current to the new release directory.
  3. Caddy immediately routes all new incoming requests to the new release on :3002.
  4. Stops the previous systemd unit (SIGTERM, TimeoutStopSec=10s, KillMode=control-group), allowing in-flight requests to finish cleanly before terminating.

If health checks fail at any point, the active release stays untouched and zero users see an error.

Related