Zero-Downtime Deployment: Automating Laravel and Node.js Applications
A practical release workflow for Laravel and Node.js that keeps requests flowing with health checks, atomic releases, queue-safe migrations, and fast rollback.
Deploying an application should not mean showing customers a maintenance page, dropping active requests, or hoping a half-finished release works. Zero-downtime deployment is a release process that moves traffic from a healthy version to a new one without a planned outage. For Laravel and Node.js applications, the reliable approach combines immutable release directories, health checks, backwards-compatible changes, and an automatic way back.
“Zero downtime” is an operational goal, not a promise that failures become impossible. A database migration, overloaded worker, or external service can still cause trouble. The aim is to keep the previous release serving users until the new release has proved it can take over.
The release pattern: build, verify, switch
Avoid copying new files over the live application directory. During a copy, the web server or Node process can see a mixture of old and new files. Instead, create a separate directory for every release:
/var/www/myapp/
releases/20261102-143000/
releases/20261105-091500/
shared/
current -> releases/20261105-091500
The shared directory holds persistent data such as uploads and environment configuration. Each new build is prepared in its own release directory, installed, and checked before current is changed. Switching a symlink on the same filesystem is atomic: new requests resolve to the new release while existing processes finish their work.
Keep several previous releases. A rollback then changes current back to a known-good directory instead of trying to reconstruct the old application from memory.
Automate the deployment steps
A CI/CD pipeline should do more than run git pull on production. A useful sequence is:
- Run unit tests, static analysis, and dependency or security checks.
- Build a versioned artifact and record its commit identifier.
- Create a fresh release directory on the server and transfer the artifact.
- Link shared configuration and persistent storage.
- Install production dependencies and run framework-specific preparation.
- Apply safe database changes, then test the release locally.
- Switch the live symlink or route a small canary slice to the new version.
- Check application health and error rates; roll back automatically if checks fail.
Make every step repeatable. The same artifact that passed staging should be promoted to production, rather than rebuilding from a possibly different dependency state. Keep secrets in the deployment environment or secret manager, not in the artifact or repository.
Laravel: handle shared state and long-running workers
Laravel deployments need a few extra details. Keep .env outside versioned releases and link it into each release. If users upload files locally, link storage/app/public to shared storage too; otherwise a release switch can make existing uploads appear to vanish.
Install only production dependencies and build caches as part of release preparation:
composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader
php artisan config:cache
php artisan route:cache
php artisan view:cache
Run php artisan migrate --force only after checking that migrations are compatible with both the old and new code. A safer schema change has two stages: first add a nullable column or new table, deploy code that can work with both shapes, backfill data, and only later remove the old field in a separate release. A destructive migration can make rollback impossible even when the old files are still available.
Laravel queue workers are long-running processes, so they do not automatically load a newly deployed release. After the switch, gracefully restart them with php artisan queue:restart and supervise them with systemd, Supervisor, or the process manager already used by the host. Ensure the supervisor starts workers from the current path, and allow active jobs to finish. For Horizon, use its graceful termination command as part of the release hook. Schedule workers and cron jobs should also use the stable path.
Node.js: start a new process before retiring the old one
For Node.js, prepare a new release with a locked dependency install such as npm ci --omit=dev, then start it on a separate port or as a new process group. Check that it can serve a readiness endpoint and connect to required dependencies before moving traffic. A reverse proxy such as Nginx can route requests to the new process; a process manager or orchestrator can also perform a rolling restart.
The readiness check should report whether the application can serve real requests, not merely whether the process exists. Keep it fast and bounded: check critical dependencies without letting a slow optional integration make the service look permanently unavailable. Once the new process is ready, switch upstream traffic, watch errors and latency, then gracefully drain and stop the old process. Handle SIGTERM so Node closes its HTTP server and finishes or safely abandons in-flight work before its shutdown deadline.
Database changes follow the same expand-and-contract rule. Deploy code that tolerates both the existing and updated schema, backfill in manageable batches, and remove obsolete columns only after all older application processes are gone. Use feature flags when a new behavior needs to be enabled separately from the code release.
Health checks, monitoring, and rollback
Before deployment, verify disk space, artifact integrity, configuration, and access to required services. After switching, run a smoke test against the public health endpoint and a critical user path. Watch HTTP 5xx rates, response latency, queue depth, and process restarts for a short observation window. A deploy is not successful just because the command returned exit code zero.
Automated rollback should restore the previous release and restart or re-route services cleanly. It cannot undo every database change, which is why schema compatibility matters. Send a deployment notification with the commit, outcome, and rollback status so the on-call person has a clear audit trail.
A practical rollout checklist
- Build and test the exact artifact that will reach production.
- Store uploads, secrets, and environment configuration outside release folders.
- Keep at least two known-good releases available.
- Make migrations safe while old and new application versions overlap.
- Check readiness before switching traffic; drain old processes gracefully.
- Monitor errors after release and automate a quick code rollback.
Start with one service and one low-risk release. Measure how long each stage takes, practice a rollback, and add complexity only when the application needs it. With these controls, Laravel and Node.js deployments become routine, observable changes while users continue to receive responses.