How does a blue-green deployment work?

In short
A blue-green deployment is a way to release new software with little or no downtime. You run two identical production environments, called blue and green. One serves live traffic while the other receives the new version, and a router switch moves users over once the new version is tested.
The problem it solves
Releasing new software is risky. The hardest moment is the cut-over, when a tested build moves into the live system that real users depend on. If the switch is slow, users wait. If it goes wrong, users see errors until someone fixes it.
Blue-green deployment tackles this moment directly. Instead of updating the running system in place, you keep two production environments that are as identical as possible. At any time, one of them is live and the other is idle.
How it works
Imagine two environments named blue and green. Suppose blue is live and serves all incoming requests. To release a new version, you deploy it to green and run your final round of testing there. Users never touch green during this step.
When green passes its checks, you switch the router so that all incoming requests go to green. Blue is now idle. The change is a routing change, so it is fast and easy to repeat.
The next release follows the same pattern in reverse. Blue becomes the staging area for the next version, and you switch back when it is ready. Over time, both environments take turns being live, being the previous version kept for rollback, and being the staging area for the next release.
Rolling back
Rollback is one of the main benefits. If something goes wrong after the switch, you point the router back at the old environment. That environment still runs the previous version, so you do not need to rebuild anything under pressure.
The switch does not solve every problem, though. Requests that were handled by the new environment while it was live may not exist on the old one. You need a plan for those missed transactions. One option is to send transactions to both environments, so the blue one stays up to date as a backup. Another is to put the application in read-only mode before the cut-over, run it that way for a while, and then switch it to read-write mode. Either approach gives you time to find issues before they cause damage.
Databases need extra care
Databases make blue-green deployment harder, especially when a release changes the schema. A common approach is to separate schema changes from application upgrades. First, change the schema so that both the old and new versions of the application can work with it. Deploy that change and confirm everything is stable. This gives you a safe rollback point. Then deploy the new application version. Once the upgrade has settled, remove the database support that only the old version needed.
This is a practical rule: keep each database change small and backward compatible, so that either environment can read the data it expects.
Common mistakes
The biggest mistake is letting the two environments drift apart. If blue and green differ in configuration, libraries or hardware, a test on green tells you little about how blue will behave. Keep them as close to identical as you can, and automate how they are built.
Another mistake is treating the switch as the end of testing. Final checks should happen in the idle environment before the switch. After the switch, watch the system closely for a while, because some problems only appear under real traffic.
Teams also sometimes forget the data layer. A router switch moves web traffic, but it does not move data. Plan how writes are handled during the cut-over before you start.
Alternatives
Blue-green is not the only way to release safely. A rolling deployment updates instances in small groups, so the system is never fully switched at once. A canary release sends a small share of traffic to the new version first and increases it step by step. Each approach trades speed, cost and risk in a different way. Blue-green is a good fit when you can afford two full environments and want a quick, simple rollback.
If you are new to the wider idea of automated releases, our reference pages on continuous delivery are a good next step.
FAQ
Does blue-green deployment cause downtime?
It aims to avoid it. Users keep using the live environment while the new version is tested in the idle one, and the switch is a quick change in routing. Some brief disruption can still happen depending on your setup and how you handle active sessions.
Do I need two full copies of my production system?
The approach works best when the two environments are as identical as possible. That usually means paying for double the infrastructure, although the environments can be virtual machines or separate zones on the same hardware.
How is blue-green different from a rolling deployment?
A blue-green deployment switches all traffic between two complete environments at once. A rolling deployment replaces instances of the same system a few at a time, so old and new versions run side by side during the release.
What happens to database changes during a blue-green switch?
Schema changes should be deployed separately and be compatible with both the old and new application versions. This lets either environment work with the same database while you test and roll back.
Sources
This page is based on the official documentation below. Read it for full detail.
Blue-green deployment — official documentation ↗