~/writing
Zero-downtime deploys on one server
Start the new version, wait for it to be healthy, then swap. A small pattern that covers most single-box apps.
You don’t need a cluster to deploy without dropping requests. You need two copies of your app for about thirty seconds and a proxy that can switch between them.
The steps
- Start the new release on a spare port.
- Poll its health check until it answers 200, or give up after a minute.
- Point the proxy at the new port and reload it. Reloads don’t drop open connections.
- Wait for the old process to finish its requests, then stop it.
new_port=$(next_free_port)
start_release "$release" "$new_port"
wait_healthy "http://127.0.0.1:$new_port/health" 60 || { stop_release "$release"; exit 1; }
point_proxy_at "$new_port" && reload_proxy
drain_and_stop "$old_release"
The part people skip is the last one. Stopping the old process the moment the proxy switches cuts off whatever it was still answering.