Run two full copies of production, then switch the traffic from one to the other.
A blue-green deployment keeps two full copies of production. One (say Blue) serves the users. You put the new version on the other (Green), test it, and then switch the traffic over in one step.
Normally a deployment changes the servers that users are using right now. That is risky: if the new code is bad, users feel it at once. Blue-green avoids this by never touching the live servers.
You have two identical environments, called Blue and Green (the colours are only names). At any time one is live and the other is idle. A release goes like this: deploy the new version to the idle one, test it with no users on it, and then change the router so all traffic goes there. The old environment becomes the idle one, ready for the next release or for a rollback.
| Switch method | How it works | Good and bad |
|---|---|---|
| Load balancer target swap | The load balancer points to the Green servers instead of the Blue ones | Fast and clear. Existing connections may need time to drain. |
| Kubernetes service selector | A Service changes its label selector from version=blue to version=green | Simple in Kubernetes. Pods for both versions must be running. |
| DNS change | The name now points to the Green address | Easy anywhere, but caches mean some users stay on Blue for a while. Rollback is also slow. |
| Platform slot swap | A cloud platform swaps two named slots (staging and production) | One click, warms the slot first. Tied to that platform. |
If you rename a column in one step, version 1 breaks the moment the change runs, so your instant rollback is gone. See Schema Migrations for the full recipe.
Version 2 is fine. The database change works with both versions (expand first, clean up later).
A simplified model. The failing share (30%) and server counts are illustrative, not measurements. Try each bug type, and try a breaking database change before you roll back.
| Term | Meaning in easy words |
|---|---|
| Environment | A full copy of the system: servers, settings and connections |
| Blue / Green | Names for the two environments. They have no meaning beyond telling them apart |
| Live / idle (standby) | The side that serves users, and the side that is waiting |
| Router switch | The change that sends all traffic to the other environment |
| Smoke test | A quick check that the main functions of the new version work |
| Rollback | Going back to the previous version |
| Connection draining | Letting requests already in progress finish before a server stops |
| Expand and contract | Add new things first, remove old things last, so both versions work |
| Immutable deployment | New servers are built for each release instead of changing old ones |
| Zero downtime | Users do not notice any gap in service during the release |
| Warm-up | Starting caches and connections on the new side before users arrive |
| Choice | We gain | We lose |
|---|---|---|
| Blue-green instead of rolling | Instant rollback and no mixed versions | Higher cost, as there are two full copies |
| Blue-green instead of canary | Simple, clear switch | No gradual exposure: a hidden bug hits 100% of users at once |
| Keep Blue for a long time | A safe way back | Paying for idle servers |
| Shut Blue down quickly | Lower cost | Rollback needs a new deployment |
| Shared database | No data copying and no data lost on switch | Every data change must fit both versions |
| Separate database per colour | Full isolation | Hard to keep data in sync and to switch without losing writes |