Deployment health and shutdown
Deployment health separates whether a process is alive from whether it should receive new traffic. Graceful shutdown stops accepting new work and gives admitted work a bounded chance to finish. Liveness should indicate a process that needs restarting, not every brief downstream outage. Readiness can fall when a critical dependency or drain state prevents serving. On SIGTERM, mark unready, stop new admission, close listeners, wait for in-flight work within a deadline, close resources, then exit. Long-lived connections need explicit policy. Coordinate the application deadline with the external supervisor or orchestrator grace period. Do not make every readiness failure restart the process or use immediate process.exit as the normal drain path. Sources: https://kubernetes.io/docs/concepts/workloads/pods/probes/.
Formal Syntax & Structure
Serve separate health endpoints (conceptual contract; see example)Working Example
import assert from 'node:assert/strict';import http from 'node:http';import {once} from 'node:events';let ready=true;const server=http.createServer((req,res)=>{res.statusCode=req.url==='/live'?200:req.url==='/ready'?(ready?200:503):404;res.end();});server.listen(0,'127.0.0.1');await once(server,'listening');try{const base=`http://127.0.0.1:${server.address().port}`;const status=async p=>{const r=await fetch(base+p);await r.text();return r.status;};assert.equal(await status('/ready'),200);ready=false;console.log(await status('/ready'),await status('/live'));}finally{server.closeAllConnections();server.close();}