Zero-Downtime Deployments for Laravel
A deploy should be a non-event. Users should never notice, and you should never hold your breath. Getting there is mostly about sequencing and atomicity.
Atomic Releases
The core idea is that a release either fully happens or does not happen at all. No half-updated file trees serving traffic.
Symlinked Releases
Deploy each release into a timestamped directory and flip a `current` symlink once it is fully built. Rollback becomes repointing the symlink at the previous release.
Warm the Caches
Before switching traffic, run `config:cache`, `route:cache`, `view:cache`, and `event:cache` on the new release so the first request is not the one that pays to compile everything.
Migrations Without Locks
Schema changes are where zero-downtime deploys usually break. The trick is to make every migration backward compatible.
Expand and Contract
Split risky changes into two deploys: first expand the schema so old and new code both work, then contract to remove the old shape after the new code is live. Never rename a column in a single deploy.
Restarting Workers Gracefully
Queue workers hold old code in memory. After a deploy, they must pick up the new release without dropping jobs.
Graceful Termination
Call `queue:restart` so workers finish their current job and exit cleanly, then let your process supervisor start fresh ones on the new release.
Closing Thoughts
Zero-downtime is not one feature; it is a set of habits: atomic release switches, backward-compatible migrations, and graceful worker restarts. Build them into the pipeline once and every deploy gets boring, which is exactly what you want.