How do I do zero-downtime deployments for a web app?
poze 3 months ago354 gadeen
Every deploy, my app is down for 20-30 seconds while the new container starts. Users see 502 errors. How do bigger sites deploy without downtime?
Dyagnostik IA
Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.
1 Repons
The principle: start the new version, wait until it's healthy, switch traffic, then stop the old one.
1. Health checks: expose /healthz (process alive) and /readyz (DB reachable, warmed up). The orchestrator only routes traffic once /readyz passes. 2. Rolling or blue-green deploys: Kubernetes Deployments do rolling updates by default (maxUnavailable: 0, maxSurge: 1). With Docker on one VM, use a reverse proxy (Caddy, Traefik, nginx) and swap upstreams; tools like Kamal automate this. 3. Graceful shutdown: on SIGTERM, stop accepting new connections, finish in-flight requests, then exit:
process.on('SIGTERM', () => server.close(() => process.exit(0)));
4. Backward-compatible database migrations: old and new code run side by side for a moment. Add columns first, deploy code, remove old columns in a later release ("expand and contract").
Most platforms (Render, Fly.io, Railway, Azure App Service slots) do steps 1–2 for you if you configure a health check.
Konekte pou di lòt moun si li te mache.
Sign in and verify your email to post an answer.