Deploying code updates to live production environments often risks brief 502 Bad Gateway errors or partial page renders during server restarts. A **Blue/Green Zero-Downtime Architecture** maintains two identical application slots (Blue on port 8081, Green on port 8083). Updates are deployed, compiled, and health-verified on the standby slot before an atomic Nginx configuration reload routes 100% of live traffic instantly.
1. Deployment Lifecycle State Transition
| Step | Target Slot | Action & Verification |
|---|---|---|
| 1. Build & Sync | Local / Standby | Runs `npx tsc`, snapshot testing, and syncs compiled JS to production via Rsync. |
| 2. Standby Restart | Standby (:8083) | Restarts standby PM2 cluster (`pm2 startOrRestart ecosystem.config.js`). |
| 3. Health Probe | Standby (:8083) | Automated curl probes `/api/health` across 12 sequential attempts (HTTP 200 required). |
| 4. Atomic Switch | Nginx Ingress | Updates `/etc/nginx/conf.d/upstream-active.conf` symlink and executes `nginx -s reload`. |
| 5. Slot Convergence | Previous Active | Restarts old active slot in the background, prewarms cache, and flushes edge buffers. |
