Zero-Downtime Node.js Reloads with Up Load Balancer

Up enables zero-downtime reloads for Node.js HTTP servers by load balancing across workers and gracefully restarting them on SIGUSR2 or file changes, preserving keep-alive connections.

Graceful Worker Reloading for Production

Up builds on the distribute load balancer to run multiple Node.js HTTP server instances (default: cpus/2 rounded up, minimum 1) in round-robin fashion. On reload via srv.reload() or SIGUSR2 signal, it spawns new workers while old ones drain existing keep-alive connections using a configurable workerTimeout (default '10s' in dev, parses '10s'/'10m'/'500ms'). This ensures zero downtime: new workers handle incoming requests immediately unless assumeReady: false, requiring workers to explicitly signal readiness via process.send({ up: 'ready' }). Auto-reload triggers on file changes with --watch, ideal for development.

Separate your HTTP server into a require-able module (e.g., http.createServer(app).listen(0) to avoid port binding conflicts). CLI example: up server.js starts on port 80; up -p 3000 -w -n 4 server.js watches files and uses 4 workers.

CLI and API Configuration

CLI flags control behavior:

  • -p/--port <port>: Listen port (default 3000).
  • -w/--watch: Auto-reload on dir changes.
  • -r/--require <mod>: Pre-require modules like 'coffee-script'.
  • -n/--number <n>: Worker count (overrides auto-calc).
  • -t/--timeout <time>: Worker drain timeout.
  • -k/--keepalive: Enforce keep-alive (default on).
  • -f/--pidfile <file>: Write PID to file.
  • -T/--title <title>: Set process.title ('up master'/'up worker').

JS API mirrors flags: new UpServer(serverModule, numWorkers, {workerTimeout: '10s', title: 'myapp', assumeReady: false, keepAlive: true, minExpectedLifetime: '20s'}). Inherits distribute's use() for middleware; final handler does round-robin. Set NODE_ENV=production for longer timeouts.

Trade-offs and Reliability

Up assumes workers are ready post-require unless configured otherwise, minimizing latency but risking unready states—use explicit readiness for complex init. Keep-alive prevents abrupt closes during drains. MIT-licensed by Guillermo Rauch (2011), focuses on Node.js ecosystems without broader cloud integration.

Summarized by x-ai/grok-4.1-fast via openrouter

5085 input / 1271 output tokens in 6120ms

© 2026 Edge