DevOps & Containers
Zero-Downtime Deployment: How to Release Updates Without Taking Your Site Offline
By NileVPS Team · Published · 4 min read
اقرأ المقال بالعربيMany sites still deploy by stopping the application, copying new files and starting it again. Even if that takes only thirty seconds, users in the middle of a checkout see errors, API clients get failed requests and monitoring fires alerts. Zero-downtime deployment is the practice of releasing new versions while the service keeps answering every request. It is not one tool but a set of techniques, and most of them work perfectly well on a single VPS.
What "zero downtime" really requires
To avoid interruptions, a deployment has to guarantee three things:
- There is always a process ready to accept new connections. The old version keeps serving until the new one is ready.
- In-flight requests are allowed to finish. Processes are stopped gracefully instead of being killed.
- Old and new versions can coexist briefly. Code, database schema, caches and sessions must tolerate both versions at the same time.
Every technique below is a way of meeting these conditions.
Technique 1: graceful reloads
Many servers can reload code or configuration without dropping connections:
- Nginx:
sudo nginx -t && sudo systemctl reload nginxstarts new workers and lets old ones finish their requests. - PHP-FPM:
sudo systemctl reload php8.3-fpm(adjust the version) gracefully replaces workers. - Gunicorn: sending
HUPreloads workers;USR2followed byWINCHandQUITto the old master allows a full binary upgrade. - Node.js with PM2:
pm2 reload apprestarts cluster-mode instances one at a time.
Graceful reloads are the simplest win, but they only cover the process level. They do not protect you from a broken release.
Technique 2: atomic symlink releases
A popular pattern for PHP, static sites and many scripting languages is to deploy each version into its own directory and switch a symlink:
/var/www/app/
releases/
20261120-1015/
20261122-0930/
shared/ # .env, uploads, storage
current -> releases/20261122-0930REL=/var/www/app/releases/$(date +%Y%m%d-%H%M)
git clone --depth 1 https://example.com/repo.git "$REL"
ln -s /var/www/app/shared/.env "$REL/.env"
cd "$REL" && composer install --no-dev --optimize-autoloader
# Atomic switch: create the new link, then rename it over the old one
ln -sfn "$REL" /var/www/app/current.tmp
mv -T /var/www/app/current.tmp /var/www/app/current
sudo systemctl reload php8.3-fpmmv -T performs a rename, which is atomic on the same filesystem, so the web server never sees a half-written directory. Rollback means pointing current back at the previous release. Keep the last few releases and delete older ones. If PHP OPcache uses realpath caching, the reload ensures the new path is picked up.
Technique 3: blue-green and rolling updates
- Blue-green: run the new version alongside the old one and switch the proxy upstream once it is healthy. See blue-green deployment for a step-by-step example with Nginx.
- Rolling update: with several instances behind a load balancer, update them one at a time, removing each from rotation while it restarts. Kubernetes Deployments do this by default with
maxUnavailableandmaxSurgesettings. - Canary: send a small share of traffic to the new version first, then increase it.
Technique 4: health checks and readiness
A proxy should only send traffic to an instance that is ready. Give your application two endpoints:
- Liveness: "the process is running" (restart me if this fails).
- Readiness: "I can serve requests now" (database connected, caches warmed, migrations compatible).
Your deploy script should poll readiness before switching:
for i in $(seq 1 30); do
curl -fsS http://127.0.0.1:8002/ready && break
sleep 2
doneIn Docker Compose you can define a healthcheck, and in Kubernetes a readinessProbe.
Technique 5: graceful shutdown
When an old instance is stopped, it should stop accepting new connections, finish current requests and then exit. In practice:
- Handle
SIGTERMin your application and close the listener first. - Give enough time before a forced kill:
TimeoutStopSecin systemd,stop_grace_periodin Compose,terminationGracePeriodSecondsin Kubernetes. - Remove the instance from the load balancer before stopping it.
The database rule: expand, migrate, contract
Schema changes cause more downtime than code changes. Follow this order:
| Step | Example |
|---|---|
| Expand | Add a new nullable column full_name |
| Deploy code that writes both | Write first_name, last_name and full_name |
| Backfill | Fill full_name for old rows in batches |
| Deploy code that reads the new column | Stop reading the old ones |
| Contract | Drop old columns in a later release |
Also watch for long locks: adding an index on a big PostgreSQL table should use CREATE INDEX CONCURRENTLY, and large updates should be batched.
Zero-downtime checklist
- Deployments are scripted and repeatable.
- Sessions live in Redis or the database, not on local disk.
- Uploads live in shared or object storage.
- Health and readiness endpoints exist and are used.
- Processes shut down gracefully on
SIGTERM. - Migrations are backward compatible.
- Rollback is one command and has been tested.
- Error rate and latency are watched for a few minutes after each release.
A VPS with snapshots gives you one more layer of safety: take a snapshot before risky changes. You can compare VPS plans if you need a second instance for blue-green or rolling releases.
FAQ
Can I achieve zero downtime on a single VPS?
Yes, for most applications. Graceful reloads, symlink releases and two app instances behind Nginx cover the process and release side. What a single server cannot protect against is the failure of the server itself; that requires a second machine.
Does zero-downtime deployment mean my site never goes down?
No. It means deployments themselves do not cause downtime. Hardware faults, network problems, bad configuration or overload can still interrupt service, so monitoring, backups and capacity planning remain necessary.
Is a maintenance page ever acceptable?
Sometimes. Very large data migrations or major infrastructure moves may justify a short, announced maintenance window. The goal is to make it a rare, planned exception rather than part of every release.