StackLift
All terms

Glossary

Blue-green deployment

A release method that runs two identical environments and switches traffic from the old to the new.

Blue-green deployment is a release strategy that keeps two identical production environments, called blue and green. One serves live traffic while you deploy and test the new version on the other. When it is ready, you switch traffic over at once, and switching back is your rollback.

The strength is a fast, low-drama rollback and a release with little or no downtime. The new version is fully tested in a production-like setting before anyone uses it.

The cost is capacity, since you run two environments at once, and the care needed with databases, because both versions must work with the same data.

Start in 60 seconds

Put this to work on your project.

Get an AI-assisted, architect-reviewed scope, cost range, and timeline. Free, no login.

The complete guide

Blue-green deployment: the complete guide

Updated November 18, 2026 ยท Published by , Founder, StackLift AI. Written with AI assistance; how we make content.

Short answer

Blue-green deployment runs two identical production environments. One (blue) serves live users while the new version is installed and tested in the other (green). When green is ready, traffic switches to it in one step. If something goes wrong, you switch back, which makes releases and rollbacks fast and low-stress.

What is blue-green deployment?

Blue-green deployment is a release technique that keeps two production-ready environments side by side. Only one serves users at a time. You prepare the new version in the idle one, check it thoroughly, then redirect traffic to it. The old environment stays untouched, ready to take traffic back.

The colors are just labels. Blue is whatever is live now. Green is whatever you are about to make live. After the switch, green becomes the live one, and blue becomes the idle one that you will use for the next release.

The point is to separate deploying from releasing. You can install and test a new version for as long as you need, while users never see it. Releasing is then a small, quick, reversible change of routing.

How does blue-green deployment work step by step?

  1. Blue is live and serves all users. Green is idle, or holds the previous version.
  2. Your CI/CD pipeline builds the new version and installs it in green.
  3. Automated checks run against green: health checks, smoke tests and key user journeys, using the same configuration and a copy of production-like data.
  4. Database changes are applied in a way both versions can work with. See the next section.
  5. A router, load balancer or DNS record switches live traffic from blue to green.
  6. Monitoring watches error rates, speed and business signals closely right after the switch.
  7. If something looks wrong, traffic switches back to blue in moments.
  8. When green has proven itself, blue is kept for a short safety window, then updated to become the next idle environment.

The switch is the only step that touches users, and it is small and reversible. That is why teams use the technique when downtime or a failed release is costly.

What about the database?

The database is the hard part. Both environments usually share one database, because two copies would drift apart as users make changes. That means both the old and the new code must work with the same data during the switch and during a rollback.

The standard answer is the expand and contract pattern. First you expand: add new columns or tables in a way the old code ignores. Then you release the new code, which uses them. Only after the new version is stable, and rollback is no longer needed, do you contract: remove the old structures.

Database changes and blue-green safety
ChangeSafe at switch time?Approach
Add a new nullable column or tableYesAdd first; old code ignores it
Rename or remove a columnNo, not in one stepAdd the new one, copy data, move code, remove the old one in a later release
Change a data typeRiskyAdd a new column, write to both, migrate, then switch reads
Backfill large amounts of dataPlan carefullyRun in the background before the switch, in batches
Destructive clean-upOnly after the rollback window endsSchedule as a separate, later release

Plan data changes in release management from the start. Teams that skip this find that rollback is fast for code and impossible for data.

Blue-green vs. canary, rolling and recreate deployments

Release strategies compared
StrategyHow it worksRollbackExtra costBest for
Blue-greenTwo full environments; switch all traffic at onceSwitch back, very fastA second environment during releasesClean cut-overs and quick rollback
Canary releaseSend a small share of traffic to the new version, then grow itSend traffic back to the old versionModerateLearning from real traffic before a full rollout
Rolling updateReplace instances a few at a timeRoll forward or redeploy the old versionLowRoutine updates of stateless services
RecreateStop the old version, start the new oneRedeploy the old versionNoneWhere downtime is acceptable
Feature flagsShip code switched off, then turn features onTurn the flag offFlag managementSeparating release from deployment at feature level

These are not rivals. Many teams use blue-green for the infrastructure switch and feature flags for the features inside it.

What are the benefits?

  • Little or no downtime: users keep using blue until green takes over.
  • Fast rollback: the old version is still running and can take traffic back.
  • Realistic testing: green is tested in a production-like environment before anyone depends on it.
  • Lower stress: releases become routine, not events that need a late night.
  • Disaster recovery practice: building a second environment forces your infrastructure to be reproducible.

What are the drawbacks and limits?

  • Cost: you run two environments, at least for a while. Cloud platforms make it cheaper by letting you create and remove the idle one on demand.
  • Database coordination: schema changes need careful, multi-step planning.
  • State: user sessions, caches and background jobs must survive the switch, or be handled deliberately.
  • All-at-once exposure: unlike a canary, all users move together, so a hidden defect reaches everyone.
  • Third-party coupling: external services, such as payment webhooks, may need to be pointed at the right environment.

If your main risk is an unknown problem that only appears under real traffic, a canary release limits the damage better. If your main risk is a slow, painful rollback, blue-green fits.

How do you adopt blue-green deployment?

  1. Make the environment reproducible: define infrastructure as code so a second copy is a command, not a project. See infrastructure as code.
  2. Keep configuration and secrets outside the code, per environment.
  3. Decide where the switch happens: load balancer, gateway, service router or DNS.
  4. Write smoke tests that prove the new version works and run them against green before the switch.
  5. Adopt expand and contract for every database change.
  6. Define the rollback trigger in advance: which signals mean switch back, and who decides.
  7. Practice the switch and the rollback in a test environment before trying them in production.
  8. Automate the whole sequence in the pipeline once the manual version is routine.

The routing layer matters. A load balancer or an API gateway switches in moments. DNS-based switches depend on caches expiring and can be slower and less predictable.

What else besides the database needs care?

Anything that holds state or runs on a schedule can behave oddly when two environments exist. Review each item before your first switch.

Stateful parts and how to handle them
PartProblem during a switchApproach
User sessionsUsers may be logged out when they move environmentsStore sessions in a shared store, not in server memory
CachesA cold cache in green slows the first requestsWarm the cache before the switch
Background jobs and queuesJobs may run twice or be lostPause or drain workers on the old side, and make jobs safe to repeat
Scheduled tasksBoth environments run the same scheduleEnable schedules only in the live environment
Webhooks and callbacksExternal services point at one addressRoute through the shared entry point so both environments receive them correctly
File uploadsFiles saved on one server are missing on the otherUse shared object storage

What tools support blue-green deployments?

Most platforms support it in some form. Cloud examples include AWS CodeDeploy, Elastic Beanstalk and Elastic Load Balancing, Azure App Service deployment slots and Google Cloud's load balancing and Cloud Run traffic splitting. Platforms such as Vercel provide instant promotion and rollback of builds.

On Kubernetes, teams run two deployments and switch a service selector, or use tools such as Argo Rollouts or Flagger. Pipelines run through GitHub Actions, GitLab CI or similar tools. Choose what fits your hosting; the idea is the same on all of them.

Serverless platforms often give you versions and aliases that behave like blue-green out of the box. See serverless.

When is blue-green a good choice?

  • A web application with steady traffic where a failed release would be visible and costly, such as checkout or booking.
  • A regulated system where releases must be rehearsed and reversible.
  • A major upgrade, such as a new framework version, that you want to test fully before users touch it.
  • A cut-over from an old platform to a new one, where the old stays warm as a fallback.
  • A product with a defined maintenance mindset and a team that wants predictable, calm releases.

It is a weaker fit for tiny projects where a short maintenance window is acceptable, or for stateful systems whose data cannot be shared between versions.

What mistakes should you avoid?

  • Letting blue and green drift apart in configuration, so green is not a true copy.
  • Making a destructive database change in the same release as the code.
  • Switching with no monitoring plan, so a problem goes unnoticed.
  • Shutting down blue immediately, which removes the fast rollback.
  • Never practicing the rollback, so it fails when needed.
  • Forgetting background workers and scheduled jobs, which may run in both environments at once.

How do you know it is working?

  • Releases cause little or no visible downtime.
  • Time to roll back is short, and the rollback has been tested.
  • Release frequency rises because releases feel safe.
  • Failed releases are caught in green, before the switch.
  • Error and latency signals stay steady across the switch.

Set targets with service level objectives, and use observability to compare the minutes before and after each switch.

What does blue-green deployment mean for cost and timeline?

The effort is mostly up-front: reproducible infrastructure, a switchable routing layer, smoke tests and disciplined database changes. After that, each release is routine. Running costs depend on how long the second environment exists and how large it is.

It is part of the delivery pipeline work in cloud and DevOps cost. The production readiness checklist lists what to have before go-live, and the free estimate scopes your pipeline.

How StackLift approaches releases

CI/CD, observability, security review and rollback are part of the plan from sprint one. Whether a project uses blue-green, canary releases, feature flags or a simpler path depends on the product and its risks, and an architect reviews that choice during scoping.

Clients see releases in the client portal, agents work on feature branches, and engineers own the decisions. See AI software factory and delivery operations.

Questions people ask

What happens to users who are mid-request during the switch?

Well-built setups let in-flight requests finish on the old environment while new ones go to the new one, a pattern called connection draining. Shared session storage means users stay signed in after the move.

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

Blue-green switches all traffic at once between two full environments. A canary sends a small share of traffic to the new version first and grows it gradually. Canaries limit exposure; blue-green gives a clean cut-over and quick rollback.

Does blue-green deployment cause downtime?

It can avoid it, since users stay on the old environment until the new one is ready. Brief effects can still occur from session handling, caches or database changes if they are not planned.

Do both environments share a database?

Usually yes. That is why schema changes follow an expand and contract pattern so both code versions can work with the same data.

Is blue-green deployment expensive?

It needs a second environment during releases. Many teams create the idle one on demand and remove it afterward, which keeps cost down.

Can I do blue-green on Kubernetes or serverless?

Yes. On Kubernetes you run two deployments and switch traffic, or use a rollout tool. Many serverless platforms offer versions and aliases that work the same way.

How long should I keep the old environment?

Long enough to be confident in the new version, which depends on your traffic patterns and risk. Keep it until the rollback window closes, then reuse it.

Is blue-green only for large companies?

No. Any team with reproducible infrastructure and a routing layer can use it. Small teams get the most from the calm, reversible releases.

How does blue-green relate to feature flags?

They complement each other. Blue-green controls which version of the application is live. Feature flags control which features inside that version are visible.

Sources

Sources and further reading

The standards, rules, research and official documentation this page draws on.