Back to blog
Deploy8 min read

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 downtimeSymptomFix
The gap between stop and readyA few seconds of 502/503 after every deployStart the new version alongside the old one, then switch traffic
In-flight requests cut offRandom errors mid-upload or mid-paymentGraceful shutdown that handles SIGTERM
Cold startThe first requests are very slowReadiness checks and cache warm-up before taking traffic
Incompatible database change"Column not found" in the old or new versionThe expand / contract pattern
Browser and server version mismatchErrors on a page the user already had openKeep the previous version's static files around for a while
Long-lived connectionsWebSockets or streams dropping suddenlyDrain 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.

Comparison of rolling, blue/green and artifact promotion

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.

app/api/health/route.ts
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:

server.ts
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:

Four steps for a database change without downtime: expand, dual write, release, contract

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.

The release loop on Parslinks is designed around exactly this:

  1. Every branch gets its own build and preview.
  2. If there's a database change, run the compatible migration before promoting.
  3. The approved build is promoted to production, and the previous version stays warm while the new one stays healthy.
  4. 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

      تشتتت