Zero-downtime deployment, on your own server.
Zero-downtime deployment means releasing a new version of a site without a moment where visitors get errors or a half-updated app. ServerDog does it with releases: each deploy is built in a new folder next to the live one, and the site switches to it in one step, only after the build has finished. Earlier releases are kept, so you can roll back with a click.
By ServerDog. Updated .
Key facts
- Zero-downtime deployment means releasing a new version of a site without visitors seeing an error or a maintenance page.
- On a single server the usual method is to build each release in its own folder, then switch the live link to it in one step.
- ServerDog keeps 5 releases by default (adjustable from 2 to 50) and can switch back to any of them. A rollback does not reverse database migrations.
- If a deploy fails before the switch, ServerDog removes the unfinished release and the site keeps serving the previous one.
- With Deploy on Push, the server checks the repository every minute itself, so there is no webhook to set up.
How does a zero-downtime deploy work in ServerDog?
Every deploy goes through the same phases, and the app shows each one as it happens:
- A new release. The server fetches your branch into a fresh release folder and links the files every release shares. The live site is untouched.
- The script, up to
$ACTIVATE_RELEASE(). Your build runs inside the new folder: Composer, npm, migrations. - The switch.
currentis pointed at the new release in one step. From the next request on, visitors get the new version. - The rest of the script. Anything after the marker runs against the live release, such as restarting queue workers.
- Cleanup. ServerDog keeps the most recent releases and deletes older ones.
Until the switch, the site keeps serving the previous release. If you cancel a deploy before that point, its release is deleted and the site is untouched.
The deploy script is yours to read
Each site has a deploy script you can open and change. Three markers tell ServerDog where the release begins, where the site switches over and when to restart workers. This is the default script for a Laravel site:
$CREATE_RELEASE() cd $SERVERDOG_RELEASE_DIRECTORY $SERVERDOG_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader npm ci npm run build $SERVERDOG_PHP artisan migrate --force $ACTIVATE_RELEASE() $RESTART_QUEUES()
Coming from a hosted panel? Paste a Laravel Forge deploy script and ServerDog offers to rename its$FORGE_ variables to their $SERVERDOG_ equivalents. See the Forge comparison.
Rollback and health checks
Because each release is a complete folder, going back is as quick as going forward. Pick an earlier release, chooseRoll Back to This Release, and the site switches to it.
You can also give a site a health check path, such as /up. ServerDog requests it after each deploy, and an error status marks the deploy as failed. A deploy that runs past its timeout is stopped and its release removed.
Deploy on push, without a webhook
Turn on Deploy on Push and the server deploys your branch within a minute of each new commit. The server checks the repository itself, so there is no webhook to set up and your Mac doesn’t need to be awake.
What are the zero-downtime deployment strategies?
There are several ways to deploy without downtime. They differ in how many copies of the app run at once:
- Release folders with an atomic switch. One server, several release folders, one link that says which is live. Simple and fast. This is what ServerDog does.
- Blue-green. Two complete environments; traffic moves from one to the other at the load balancer.
- Rolling. Servers or containers are updated a few at a time behind a load balancer.
- Canary. A small share of traffic goes to the new version first, and the rest follows if it behaves.
For a site on one or a few servers, release folders give you the benefit that matters, no broken requests during a deploy, without running a second copy of everything.
When do you not need zero-downtime deployment?
ServerDog can also deploy in place, updating the site’s folder directly. That suits a simple site such as WordPress, but a failed deploy can leave it half-updated and there are no releases to roll back to. You choose between the two when you create the site.
Go deeper
Questions
What is zero-downtime deployment?
Zero-downtime deployment is a way of releasing a new version of a site without a moment where visitors see errors or a half-updated application. The new version is prepared alongside the running one, and traffic switches to it only when it is ready.
How do you achieve zero-downtime deployment on a single server?
Build each release in its own folder, then switch a “current” link to the new folder in one step once the build has finished. The web server keeps serving the old release until the switch, so there is no window where code is half copied. This is how ServerDog deploys.
Which platforms support zero-downtime deployment?
Hosted panels such as Laravel Forge and Ploi support it, as do deploy tools such as Envoyer, Deployer and Kamal. ServerDog supports it from a Mac app, on your own server, without a hosted service.
Can I roll back a zero-downtime deploy?
Yes. ServerDog keeps the most recent releases on the server, and Roll Back to This Release switches the site back to any of them. Older releases are deleted after a successful deploy.
Do database migrations cause downtime?
Not by themselves. In ServerDog’s default Laravel script, migrations run in the new release before the site switches to it. A migration that removes or renames something the old code still uses can break requests during that window, so make such changes in two deploys.
What happens if a deploy fails?
If the script fails before the switch, the site keeps serving the previous release. ServerDog can also request a health check URL after each deploy and mark the deploy as failed if it returns an error.
Last updated by ServerDog.