Zero-downtime deployments in practice: rolling, blue/green, and promoting the same artifact
Downtime rarely comes from the code itself. It comes from the few seconds between "stopped" and "ready".
Friday, 6pm. Someone finds a small bug on the checkout page, and the fix is three lines. You push it to the server and restart the process. For about forty seconds, until the app is fully back, Nginx returns 502. In those forty seconds, two orders fail and one customer gets charged twice.
Most teams have a version of this story. "Zero downtime" sounds like expensive tooling and complex infrastructure, but in practice it mostly comes down to a few simple rules: the new version is ready before it takes traffic, the old version shuts down after it finishes its work, and the database works with both.
Where does downtime actually come from?
Before choosing a strategy, it helps to know exactly what causes the outage. In most web apps, these six are to blame:
| Source of downtime | Symptom | Fix |
|---|---|---|
| The gap between stop and ready | A few seconds of 502/503 after every deploy | Start the new version alongside the old one, then switch traffic |
| In-flight requests cut off | Random errors mid-upload or mid-payment | Graceful shutdown that handles SIGTERM |
| Cold start | The first requests are very slow | Readiness checks and cache warm-up before taking traffic |
| Incompatible database change | "Column not found" in the old or new version | The expand / contract pattern |
| Browser and server version mismatch | Errors on a page the user already had open | Keep the previous version's static files around for a while |
| Long-lived connections | WebSockets or streams dropping suddenly | Drain connections and reconnect automatically on the client |
Three common strategies
All three aim for the same thing: there's never a moment when no healthy version is taking traffic. They differ in cost, rollback speed and complexity.
Rolling: gradual replacement
If you run several instances, you replace them one at a time: a new instance comes up, its health is confirmed, an old one shuts down, and repeat. It needs few extra resources and works well for stateless services. The downside: for a while two versions serve traffic at once, and rolling back has to happen the same gradual way.
Blue/green: two full environments
A complete environment with the new version (green) comes up next to the current one (blue). Once green is tested, all traffic moves over in one go and blue stays untouched. Rolling back means sending traffic back to blue: instant and simple. The cost is that you need double the resources for a while.
Promoting the same artifact
This is the approach platforms like Parslinks take. Every push produces an independent build that you review on a preview. Promoting to production means that same approved build, without rebuilding, starts taking production traffic, while the previous version stays warm until the new one proves healthy. In practice it's blue/green plus one important rule: what runs in production is exactly what you looked at.
Two things your code has to do
No release strategy replaces these two.
A readiness check. The platform or load balancer needs to be able to ask "are you ready?" and get an honest answer. A simple route that returns 200 only when the database connection is up is enough. Keep it light; it gets called every few seconds.
import { db } from "@/lib/db";
export const dynamic = "force-dynamic";
export async function GET() {
try {
// The lightest possible query; we only want to know the connection is alive
await db.$queryRaw`SELECT 1`;
return Response.json({ ok: true, version: process.env.DEPLOYMENT_ID ?? "dev" });
} catch {
return Response.json({ ok: false }, { status: 503 });
}
}Graceful shutdown. When it's time to stop the old version, the system sends SIGTERM and waits a few seconds. If the app dies instantly, in-flight requests are cut off. It's enough to stop accepting new connections when the signal arrives and let current requests finish:
const server = app.listen(port);
process.on("SIGTERM", () => {
// Stop accepting new connections; let in-flight requests finish
server.close(async () => {
await db.$disconnect();
process.exit(0);
});
// If it takes longer than 25 seconds, exit anyway
setTimeout(() => process.exit(1), 25_000).unref();
});The hardest part: the database
You can swap code in seconds, but the database is shared. With all three strategies, the old and new versions work against the same database for a while. If the new version drops or renames a column the old one still reads, you have an outage at that exact moment, however polished your release process is.
The fix is to split incompatible changes into several small, compatible releases:
Rollback: what comes back and what doesn't
Rolling back restores code, not data. Emails that were sent, messages that went onto a queue, and rows written to the database all stay where they are. That's why expand/contract isn't only about zero-downtime releases; it also makes rollback safe, because the previous version still works with the current database schema.
On Parslinks
The release loop on Parslinks is designed around exactly this:
- Every branch gets its own build and preview.
- If there's a database change, run the compatible migration before promoting.
- The approved build is promoted to production, and the previous version stays warm while the new one stays healthy.
- Watch error rate and latency for a few minutes after promoting; if they spike, roll back to the last healthy version.
Decide who is allowed to promote to production, and make a green preview a precondition for promotion. Those two simple rules prevent more Friday-evening incidents than any tool.
Frequently asked questions
Join the discussion
- EY
ehsan yaghmori
jsj
- EY
ehsan yaghmori
تست 2
- EY
ehsan yaghmori
تست
- EY
ehsan yaghmori
تشتتت
Related posts
November 24, 2026
Connecting a domain to your app: A, CNAME, the apex, and why DNS changes seem slow
You've connected the domain, but half the team still sees the old site. This post explains which record goes on the apex and which on www, how TTL slows a switch down, and how to use dig to see what the rest of the world actually sees.
November 24, 2026
Deploying Next.js to production: what SSG, ISR and SSR each need from your infrastructure
Each page's rendering mode decides what your server has to do. This post covers what SSG, ISR, SSR and PPR need from your infrastructure, how standalone output works, and what breaks once the app runs on more than one instance.
November 24, 2026
A Vercel alternative for teams in Iran: what it actually has to replace
Foreign-card payments, the risk of a suspended account and unreliable access to vercel.app push teams in Iran to look elsewhere. But renting a server and running next start covers only a small part of what Vercel did. Here is the full list, and how the alternatives compare.
