Episode 17 built the CI/CD pipeline: push code to main, tests run, then the deploy goes to the server automatically. But an automatic deploy isn’t necessarily a zero-downtime one — restart the app while a user is entering an expense and their request fails with a 502. This episode finishes the last step: shipping the new version without users noticing, and rolling back in seconds.
Why Stop-and-Restart Deploys Cause Downtime
The simplest deploy is: stop the service, pull the new code, run migrations, then start again. In the gap between stopping and the new app being ready, every request fails — with Gunicorn, usually 5–30 seconds. A zero-downtime deploy removes that gap by always keeping at least one version of the app running.
The Golden Rule: Migrations First, Code Second
The correct order for every deploy is: pull the new code, run migrations, then restart the app.…