HomeBlogHow to Implement Zero-Downtime Deployment

Engineering Guide · 9 min read · October 14, 2026

How to Implement Zero-Downtime Deployment

Scheduled 2 AM maintenance windows frustrate global customers and hide fragile release tooling. Learn how to implement true zero-downtime deployments using atomic symlink or blue-green cutovers, graceful worker draining, expand-and-contract SQL migrations, and fast health-checked rollbacks.

Author
Smit Desai
Published
October 14, 2026
Read time
9 min read
Topic
Cloud & DevOps
Services
Custom Web · Mobile Apps · All Services

For many enterprise software teams, "deployment" still means putting up a maintenance banner at midnight, running git pull, restarting PHP-FPM or Node, and hoping nobody clicks "Checkout" during the next forty seconds. If your customers operate across London, Dubai, and Singapore, there is no safe midnight window—someone is always logged in, running a payroll export, or paying an invoice.

True zero-downtime deployment is not a single tool or magic flag. It is an engineering discipline across four layers: traffic routing, process shutdown, database schema evolution, and frontend asset compatibility. Having shipped over 170 production systems and managed 300+ WordPress sites at server level for a Finnish partner, I have seen almost every outage trace back to skipping one of those four layers.

Where Standard Deployments Drop Requests and Corrupt Jobs

When a naive deployment script runs git pull && composer install && php artisan migrate && systemctl reload php-fpm directly on a live directory, three failure modes occur simultaneously:

  1. Mixed-version file reads: For several seconds, half the new files exist alongside half the old files. An incoming HTTP request loads an updated controller referencing a helper class that hasn't finished extracting.
  2. Hard-terminated TCP connections: Killing application workers mid-request leaves the reverse proxy holding broken sockets, surfacing HTTP 502 Bad Gateway errors to active users.
  3. Locked database tables: Running ALTER TABLE orders ADD COLUMN ... or dropping a column breaks the older code still serving requests on another server—or locks a 40-million-row table during peak traffic.

Solving these requires decoupling build, cutover, and cleanup.

Blue-Green vs. Rolling Updates vs. Canary Releases

Choosing the right traffic-switching topology depends on your infrastructure footprint, statefulness, and budget.

Strategy How Traffic Shifts Rollback Speed Compute Overhead Best Fit
Atomic Symlink (Single/Multi-VM) Build in /releases/<sha>, flip current symlink atomically Seconds (re-point symlink) Minimal (disk only) Laravel/Rails/Node on VMs
Blue-Green Spin up full new fleet (green), switch ALB/Nginx target Instant (switch target back) 2x compute during deploy High-compliance enterprise apps
Rolling Update Replace containers/instances in small batches (e.g., 25%) Moderate (re-deploy old image) +25% burst capacity Stateless Kubernetes/ECS services
Canary Route 5% of traffic to new release, observe metrics, ramp to 100% Instant (set weight to 0%) Minimal to moderate High-throughput APIs and SaaS

Regardless of topology, never compile assets or install dependencies in the live serving directory. Build an immutable Docker image or release directory first, verify it passes basic boot checks, and only then route live user traffic to it.

Expand-and-Contract Database Migrations Without Table Locks

Code can switch instantaneously, but a relational database is shared state. During a rolling or blue-green cutover, both Release N and Release N+1 will talk to the same PostgreSQL or MySQL database—if only for thirty seconds while in-flight requests drain.

That means every schema migration must be backward-compatible with the currently running code. Never rename or drop a column in the same release that removes references to it. Instead, follow the four-step Expand-and-Contract pattern:

  1. Expand: Add the new column as nullable (never NOT NULL without a default on large legacy engines), and deploy code that writes to both old and new columns while still reading from the old one.
  2. Backfill: Run an idempotent background job in small batches (e.g., 1,000 rows per transaction with brief sleeps) to copy historical data without exhausting IOPS.
  3. Switch Reads: Deploy code that reads from the new column (with a fallback if needed) and writes only to the new column.
  4. Contract: In a later deployment, once old workers and cached containers are gone, drop the deprecated column.
-- Step 1 (Safe): Non-blocking additive change in PostgreSQL
ALTER TABLE invoices ADD COLUMN customer_tax_id VARCHAR(64) NULL;

-- Always build indexes concurrently in production to avoid write locks
CREATE INDEX CONCURRENTLY idx_invoices_customer_tax_id
    ON invoices (customer_tax_id);

In PostgreSQL, adding CONCURRENTLY prevents holding an ACCESS EXCLUSIVE lock that blocks INSERT and UPDATE queries while indexing millions of rows. Keep lock_timeout short (e.g., SET lock_timeout = '2s';) inside migration wrappers so a blocked ALTER fails fast instead of queuing behind a long analytics query and freezing every web request behind it.

Graceful Shutdown for Web Processes and Background Workers

Even with perfect blue-green routing, users experience errors if your containers or worker processes exit abruptly on deploy. When a load balancer removes an instance from a target group, two things must happen cleanly:

  • The load balancer stops sending new requests and waits for its deregistration delay (draining period, typically 30–60 seconds).
  • The application handles SIGTERM by marking /health/ready as 503 (so no new traffic arrives) while allowing in-flight HTTP requests and active queue jobs to finish cleanly.

If you run queue workers—for example, Horizon or Supervisor processes—always trigger graceful termination rather than restarting blindly. In a containerized setup, make sure your entrypoint forwards signals properly (use exec in shell scripts so PID 1 isn't /bin/sh swallowing SIGTERM). For deeper queue resilience patterns during deployments, see our guide on scaling background jobs and queues in Laravel and Redis.

# Example Nginx / PHP-FPM OPcache safety on atomic symlink releases
location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    include fastcgi_params;
    # $realpath_root resolves the symlink once per request so OPcache
    # never mixes files across release directories mid-deploy
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
}

That $realpath_root directive is a classic real-world save: without it, PHP's OPcache caches symlink paths rather than physical release paths, causing subtle stale-code bugs after atomic directory swaps until FPM is reloaded gracefully with USR2.

Automated Health Probes and One-Command Rollbacks

Zero-downtime releases fail silently when health checks only return 200 OK from a static Nginx route. Split your health endpoints into two distinct checks:

  • /health/live: Confirms the process event loop is responsive (no DB check—otherwise a temporary DB blip restarts your entire fleet at once).
  • /health/ready: Verifies database connectivity, Redis availability, and required config before the load balancer admits traffic to the new release.

Before cutting over traffic, your pipeline should poll /health/ready on the green target until it returns consecutive 200 responses. Also keep your compiled frontend assets (manifest.json / hashed JS bundles) from the previous release available for 24 hours on shared object storage or a CDN. Otherwise, a user whose browser tab stayed open during a deploy will request an old lazy-loaded JS chunk and hit a 404.

When an error spike occurs post-cutover, rollback must be automated and tested—never improvised under pressure. Pointing the load balancer back to the blue fleet or re-symlinking the prior release artifact should take under 30 seconds, as emphasized in release engineering practices across the CNCF Blog and GitHub Engineering.

Scoping Zero-Downtime Delivery With SmitDev

Enterprises rarely fail at zero-downtime deployment because they lack tools—they fail because legacy database schemas, sticky sessions, and unmonitored queue workers were never audited before automating releases. At SmitDev, I work directly with CTOs and engineering leads as a senior Forward Deployed Software Engineer to untangle brittle deployment pipelines and turn releases into boring, daytime events.

You can engage me directly at $55/day for 8–9 hours of dedicated engineering, lock in predictable velocity with $1,999/month dedicated delivery, or align with European business hours via hire a remote developer in Europe. If your team is tired of late-night maintenance windows or needs help upgrading legacy release pipelines through upgrade old software, contact me to review your deployment architecture.

Written by Smit Desai · Principal Full-Stack & FDSE

8+ years shipping production systems · 171 case studies · 300+ WordPress servers managed for Finland partners.

Next Steps and Recommended Resources

Next Steps · Recommended Resources

Pillar 1 · Infrastructure Proof

300+ WordPress & Cloud Server Fleet

From server-level management of 300+ WordPress sites for a Finland client to PostgreSQL query tuning (3,982 -> 52 queries).

Pillar 2 · Legacy Rescue

Upgrade Old Software (10 Hrs Free)

Audit bottlenecks, eliminate security vulnerabilities, and stabilize production servers—starting with 10 free engineering hours.

01 — Frequently asked questions

cloud & devops

Why do deployments still return 502 errors even behind a load balancer?

Most 502 spikes happen because the application server is killed immediately while the load balancer still holds open keep-alive connections or hasn't finished failing its health check interval. Proper connection draining and SIGTERM handling solve this.

How do you run destructive database changes like renaming a column with zero downtime?

Use the expand-and-contract pattern across multiple releases: add the new column and dual-write to both, backfill existing rows in batches, switch reads to the new column, and drop the old column only after the previous code version is completely gone.

Is blue-green deployment always better than rolling updates?

Blue-green gives instant traffic cutover and near-instant rollback at the cost of temporarily doubling compute capacity during releases. Rolling updates use less spare capacity but require strict backward compatibility while old and new pods serve requests simultaneously.

What happens to background jobs and cron tasks during a deployment?

Workers must receive SIGTERM or a supervisor restart signal so they finish their current job before exiting, rather than being killed mid-transaction with SIGKILL.

03 — Have an engineering need?

hire the right expertise

Let's talk tech.

Deciding between an embedded forward deployed engineer or a senior full stack developer? Share your technical context and timeline.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.