StackPractices
intermediate By Mathias Paulenko

Blue-Green Deployment Pattern

Catalog entry for the blue-green deployment pattern: the problem it solves, its traffic-switch mechanism, trade-offs, and when to choose it.

Overview

The Blue-Green Deployment Pattern keeps two production-capable environments side by side. One serves live traffic; the other waits idle or warm. A release deploys to the inactive environment, validates it there, and then changes the traffic switch so users arrive at the new version. Rollback is the same routing change in reverse.

This is the catalog entry for the pattern: the problem it solves, its shape, its forces, and its consequences. Operational decisions such as switch mechanisms, sizing, rollout timelines, database migration order, and rollback thresholds belong to the Blue-Green Deployment Guide. Concrete Nginx, Kubernetes, Route 53, and CI/CD implementations live in the Blue-Green Deployment recipe. For blue-green compared with rolling and canary releases, use the deployment strategies guide.

Problem

In-place deployment couples three events that teams often need to separate: installing new code, exposing it to users, and being able to undo it. If the upgrade requires downtime, users see the release. If instances are replaced one by one, two versions coexist without an explicit compatibility plan. If the release fails, rolling back usually means rebuilding or redeploying the old version while the incident is already underway.

Blue-green separates those events. The new version is installed out of the traffic path, exposed only when the switch flips, and undone by flipping the switch back while the old version is still running.

When to Use

Use the Blue-Green Deployment Pattern when:

  • Rollback speed matters more than infrastructure cost
  • The service is stateless or its state is externalized
  • Two environments can be provisioned with the same capacity and configuration
  • A single traffic switch point exists, such as a load balancer, ingress, service selector, or API gateway
  • Releases are important enough to justify validation before exposure

Avoid it when:

  • Local state cannot move between environments
  • The release requires a destructive schema change before the switch
  • Long-lived connections cannot drain or reconnect cleanly
  • Deploys happen so often that a duplicate environment stays idle most of the time
  • A gradual exposure pattern is the real requirement; in that case use the Canary Release Pattern

Solution

The pattern is defined by four invariants, not by a specific cloud or networking product:

  1. Two equivalent environments: blue and green can each serve the full production load.
  2. One active environment at a time: users aren’t meant to straddle both versions.
  3. One explicit switch point: the release is a routing change at a single boundary.
  4. Shared durable state: both versions use the same database, cache, queues, and secret store.
# Conceptual shape, not a vendor-specific implementation
active: blue
switch_point: load_balancer
environments:
  blue:
    role: active
    version: v1
  green:
    role: standby
    version: v2
shared_state:
  - database
  - cache
  - queue
rollback: repoint_switch_to_blue

The implementation may be an AWS target-group change, a Kubernetes Service selector, an Nginx upstream swap, or a DNS record. Those are realizations of the pattern, not the pattern itself.

Explanation

The lifecycle has four phases:

  1. Deploy: install the new version on the inactive environment.
  2. Validate: test that environment directly, without exposing it to users.
  3. Switch: repoint traffic at the new environment.
  4. Retain or reverse: keep the previous version warm for rollback, then reuse it for the next release once the new version is accepted.
Blue-green lifecycle: deploy to the idle environment, validate it, switch traffic, and keep the old environment available for rollback.

The pattern deliberately leaves several questions open: how long validation lasts, which metrics trigger rollback, how schema changes are sequenced, when the old environment scales down, and how much warm capacity is worth paying for. Those are operational decisions, so they belong in the dedicated guide rather than in this catalog entry.

Variants

VariantPattern changeWhen it fits
Rolling blue-greenTraffic moves in weighted steps instead of one flipLarge fleets that cannot absorb an instant cutover
Canary blue-greenA small percentage reaches green before the full switchTeams that want production validation before full exposure
Shadow-enabled blue-greenGreen receives mirrored traffic before activationLoad-sensitive rewrites that need realistic validation
Blue-green with drainingExisting connections finish before the old environment exitsWebSockets, SSE, uploads, and long-running requests

Variants don’t remove the core invariant: there’s still a small number of complete environments and an explicit traffic boundary. Once traffic is continuously shaped across many versions or user cohorts, the design has moved into progressive delivery rather than classic blue-green.

Trade-offs

  • Cost is structural: two production-capable environments cost money even if one is idle. Scaling the standby down reduces cost but also reduces rollback readiness.
  • The database constrains the pattern: both versions usually share one schema, so changes must remain backward-compatible until rollback is no longer possible.
  • Traffic rollback isn’t data rollback: switching back restores the old code path, but writes produced by the new version remain in shared state and may need reconciliation.
  • In-flight work doesn’t move: requests, batches, WebSockets, and uploads need draining, timeouts, or client retry behavior.
  • Equivalence decays: without infrastructure as code, blue and green drift apart and the standby environment stops being a trustworthy replica.

What Works

  • Define the switch point before choosing tools; the routing boundary is the design decision.
  • Externalize sessions and mutable state so either environment can serve any user.
  • Provision both environments from the same infrastructure definitions.
  • Keep the inactive environment warm enough to make rollback real.
  • Test the reverse switch as deliberately as the forward switch.
  • Use feature flags for product exposure when infrastructure rollout and user release need separate controls.

Common Mistakes

  • Treating DNS as instant when resolver caching makes propagation uneven
  • Smoke-testing only process health instead of real dependencies and critical transactions
  • Scaling green below production capacity and discovering the difference only after the switch
  • Removing old schema elements before the rollback window has closed
  • Running scheduled jobs or queue consumers in both environments without an ownership rule
  • Assuming a router rollback also repairs bad rows written by the new version

Further Reading

Frequently Asked Questions

Is blue-green a deployment pattern or a deployment strategy?

It's both at different levels of abstraction. As a pattern, it describes a reusable arrangement of environments, state, and traffic switching. As a strategy, it becomes a set of operational choices about cost, timing, metrics, and migration order. This page covers the pattern; the guide covers the strategy in production.

What is the difference between blue-green and canary deployment?

Blue-green changes the active environment in one cutover and is built for fast reversal. Canary exposes the new version to a small slice of traffic first and is built to limit blast radius. They can be combined, but they answer different risk questions.

Does blue-green require two databases?

No. Most blue-green systems share one database, cache, and queue layer. Duplicating durable state creates a harder problem: writes accepted by one environment during the release may be invisible or lost after a rollback.

When is blue-green the wrong pattern?

It's the wrong pattern when local state can't move, destructive schema changes must happen atomically with the release, or connections can't drain safely. It's also a poor default for high-frequency low-risk deploys, where rolling releases are usually cheaper and simpler.