Dev tools

Blue Green Deployment: How It Works and When to Use It

Blue green deployment explained: how it works, a Kubernetes example, databases, costs, blue green vs canary and rolling deployments, and when to use each.

By OmniAI Editorial · Nov 22, 2026 · 11 min read

Blue green deployment is a release technique that runs two identical production environments: "blue" serves live traffic while "green" receives the new version. Once green passes its checks, you switch traffic from blue to green in one step, usually at the load balancer or router. If something goes wrong, you switch back just as quickly, because blue is still running the old version. The result is near-zero downtime and instant rollback, at the cost of running extra infrastructure and handling database changes carefully.

This guide explains how blue green deployment works, a blue green deployment example on Kubernetes, how to deal with databases and sessions, what it costs, blue green vs canary deployment, blue green deployment vs rolling updates, cloud services that support it, and when to choose each strategy.

What Is Blue Green Deployment?

The technique was named by Daniel Terhorst-North and Jez Humble and popularised in Humble and Dave Farley's book Continuous Delivery; Martin Fowler's well-known 2010 description sums up the idea as having two easily switchable environments. The colours have no meaning beyond telling the two apart.

The core properties:

  • Two production-ready environments that are as identical as possible: same infrastructure, configuration and capacity.
  • One live at a time. Users only reach the active environment.
  • An atomic switch. Traffic moves from one environment to the other through a single change at the router, load balancer, DNS or service mesh.
  • A ready rollback. The previous environment stays up until you're confident in the new one.

After a successful release, the roles flip: green is now live, and blue becomes the target for the next release.

How Blue Green Deployment Works, Step by Step

  1. Blue is live. All production traffic goes to blue, running version 1.
  2. Deploy to green. Provision or update the green environment with version 2. Users see nothing yet.
  3. Test green. Run smoke tests, integration tests and health checks against green using an internal URL or a preview route. Some teams send synthetic traffic or mirror a copy of real requests.
  4. Switch traffic. Point the router, load balancer or service at green. New requests now go to version 2.
  5. Monitor. Watch error rates, latency and business metrics closely for the first minutes and hours.
  6. Roll back if needed. If problems appear, point traffic back to blue, which is still running version 1.
  7. Retire or recycle blue. Once you're confident, scale blue down, keep it as a standby, or use it for the next release.
A grey router with an orange dot above two server stacks, a solid ink arrow to the grey stack on the right and a dotted ink arrow back to the light stack on the left.
Traffic moves to the new environment in one step, and can move back just as fast.

Blue Green Deployment Example on Kubernetes

Here's a simple blue green deployment example using plain Kubernetes. You run two Deployments, one labelled version: blue and one version: green, and a Service whose selector decides which pods receive traffic:

apiVersion: v1
kind: Service
metadata:
  name: shop
spec:
  selector:
    app: shop
    version: blue  # change to green to switch traffic
  ports:
  - port: 80
    targetPort: 8080

Deploy version 2 as the shop-green Deployment, wait until its pods are ready and tested, then switch the Service selector:

kubectl patch service shop -p '{"spec":{"selector":{"app":"shop","version":"green"}}}'  # traffic now goes to green

Rolling back is the same command with blue. When green has proven itself, scale the blue Deployment to zero or update it for the next release. Our Docker vs Kubernetes guide explains Services and Deployments if they're new to you.

Kubernetes Blue Green Deployment With Argo Rollouts

Doing this by hand works, but tools automate the steps. In a Kubernetes blue green deployment managed by Argo Rollouts, a Rollout resource replaces the Deployment and manages two Services: an active one for live traffic and a preview one for testing the new version.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: shop
spec:
  replicas: 3
  selector:
    matchLabels:
      app: shop
  template:
    metadata:
      labels:
        app: shop
    spec:
      containers:
      - name: shop
        image: example/shop:2.0
  strategy:
    blueGreen:
      activeService: shop-active
      previewService: shop-preview
      autoPromotionEnabled: false

When the pod template changes, Argo Rollouts creates the new ReplicaSet, points the preview Service at it, and, because autoPromotionEnabled is false, waits for you (or an automated analysis) to promote it. On promotion it switches the active Service, then scales down the old ReplicaSet after a delay (scaleDownDelaySeconds, 30 seconds by default) so network rules can update everywhere before old pods disappear.

Handling Databases, Sessions and State

The application layer is easy to duplicate; data isn't. This is where most blue green deployments get hard.

Databases. Blue and green usually share one database, which means both versions must work with the schema at the same time. Fowler's guidance is to separate schema changes from application releases: first apply a database change that supports both the old and the new version, deploy it and confirm it works, then release the new application, and remove support for the old version only after the release has bedded down. This "expand and contract" (or parallel change) pattern looks like this for renaming a column:

StepDatabase changeApplication
1. ExpandAdd the new column, keep the old oneBlue still writes the old column
2. Dual writeBackfill data; both columns kept in syncGreen reads and writes the new column, also writes the old one
3. SwitchNo changeTraffic moves to green; blue still works for rollback
4. ContractDrop the old column after a safe periodOnly green's code remains

Managed database blue/green. For database engine upgrades or major parameter changes, Amazon RDS and Aurora offer a managed Blue/Green Deployments feature that creates a synchronised staging copy of the database and switches over to it, which addresses a different problem (changing the database itself) from application blue/green.

Sessions and in-flight requests. Store sessions in a shared store such as Redis or in signed cookies, not in server memory, so users aren't logged out at the switch. Drain connections on blue rather than cutting them.

Background jobs and queues. Make sure only one environment's workers process jobs, or that jobs are safe to run twice, to avoid duplicate emails or charges.

Blue Green vs Canary Deployment

Blue green vs canary deployment is the comparison people ask about most. Both reduce release risk; they differ in how traffic moves.

Blue green deploymentCanary deployment
Traffic shiftAll at once, from blue to greenGradually: 1%, 5%, 25%, then 100%
EnvironmentsTwo full environmentsOne environment with old and new versions running side by side
Infrastructure costUp to double during the releaseSmall extra capacity for the canary
RollbackInstant switch backShift traffic back from the canary
Exposure to bugsAll users after the switchOnly the canary percentage at first
Real-user testing before full releaseLimited (preview testing only)Yes, on a slice of real traffic
ComplexitySimple concept; data handling is the hard partNeeds traffic splitting and good metrics to judge each step
Best forFast, clean cutovers and easy rollbackCatching problems that only appear under real traffic

Many teams combine them: deploy green, send a small canary slice of traffic to it, watch metrics, then switch the rest. Argo Rollouts, service meshes and most cloud load balancers support weighted traffic for exactly this.

Blue Green Deployment vs Rolling

Blue green deployment vs rolling updates is the other common comparison. A rolling update replaces instances of the old version with the new one a few at a time, which is the default strategy for Kubernetes Deployments.

Blue green deploymentRolling update
How it worksStand up a full new environment, then switchReplace old instances gradually
Mixed versions in productionBriefly, only if you combine with canaryYes, throughout the rollout
Extra capacity neededA full second environmentLittle; a few extra instances (surge)
Rollback speedInstant: switch backSlower: roll the old version out again
DowntimeNear zeroNear zero if health checks are right
Testing before users see itYes, on greenLimited; new instances take traffic as they become ready

Rolling updates are cheaper and simpler and work well for stateless services with good health checks. Blue green is better when you need a tested, complete environment before any user touches it and a guaranteed fast way back.

Three ink-outlined panels: two server stacks with an ink arrow above them, a grey stack with one orange block, and a stack whose lower blocks are light and upper blocks grey.
Blue green switches everything at once; canary tests a slice; rolling replaces instances one by one.

What Blue Green Deployment Costs

The main cost is running a second environment. How much depends on how long green exists:

ApproachExtra infrastructureExample: environment costs $10,000 a month
Permanent standby (blue and green always running at full size)About 100% moreAbout $20,000 a month
Green created per release, 2 hours per release, 20 releases a monthRoughly 40 hours of a second environmentAbout $550 extra a month
Shared databases and caches, only stateless tiers duplicatedOnly the duplicated tiersDepends on the split; often far less than double

Autoscaling, containers and infrastructure as code make short-lived green environments practical; our infrastructure as code guide covers how to define environments so they can be created and destroyed reliably. The extra cost buys faster, safer releases, which is often cheap compared with the cost of an outage.

Cloud Services That Support Blue Green

  • AWS: CodeDeploy supports blue/green deployments for Amazon ECS and EC2; Elastic Beanstalk can swap environment URLs between two environments; RDS and Aurora have managed Blue/Green Deployments for database changes.
  • Azure: App Service deployment slots let you deploy to a staging slot and swap it into production; Azure Container Apps can shift traffic between revisions using labels and traffic weights.
  • Google Cloud: Cloud Run and load balancers support traffic splitting between revisions and backends, which can implement blue/green or canary releases.
  • Kubernetes: Service selector switching, Argo Rollouts, Flagger and service meshes such as Istio.

When to Use Blue Green Deployment

Use blue green deployment when:

  • downtime during releases is unacceptable,
  • you need instant, reliable rollback,
  • you want to test the complete new environment before users reach it,
  • releases change infrastructure as well as code, or
  • you can afford the extra capacity, at least temporarily.

Choose something else when:

  • the service is stateful in ways that are hard to share between two environments,
  • the cost of a duplicate environment is prohibitive and rolling updates are good enough,
  • you need to learn how real users react before a full release (use canary), or
  • database changes can't be made backward compatible.

Common Mistakes

  • Environments that drift apart, so green behaves differently from the blue it replaces. Define both with the same code and configuration.
  • Breaking database changes deployed together with the application, making rollback impossible.
  • DNS-based switching with long TTLs, which leaves some clients on the old environment for hours.
  • Cutting off in-flight requests instead of draining connections.
  • Deleting blue too soon, removing the rollback option before problems have had time to surface.
  • Testing green lightly and treating the switch itself as the test. Our site reliability engineering guide covers the monitoring and error budgets that make releases safe.

FAQ

What is the main benefit of blue green deployment?

Near-zero downtime and instant rollback. Because the old version keeps running until you're confident in the new one, reverting is a single traffic switch rather than a redeployment.

Is blue green deployment expensive?

It can double infrastructure costs if both environments run permanently. Creating the green environment only for each release, and duplicating only stateless tiers, reduces the extra cost dramatically.

How do you handle databases in blue green deployment?

Make schema changes backward compatible and deploy them separately from the application, using expand-and-contract steps, so both versions can run against the same database during the switch.

What is red-black deployment?

It's the same idea under a different name, used by Netflix and some tools: run the old (red) and new (black) versions side by side and switch traffic between them.

Is blue green deployment the same as A/B testing?

No. Blue green deployment is a release technique that sends all traffic to one version at a time. A/B testing deliberately splits users between variants to compare their behaviour, usually for product decisions.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog