# Blue-green deployment

> Releasing a new version next to the old one and switching traffic over at once.

- Level: Intermediate
- Topics: Cloud
- URL: https://tidbit.legios.com.ar/blue-green-deployment/
- In Spanish: [Despliegue blue-green](https://tidbit.legios.com.ar/es/blue-green-deployment/)

A **blue-green deployment** is a way to release new software with almost no downtime. You keep two identical production environments. One, say blue, is serving users with the current version. You install the new version on the other, green, test it there with real infrastructure, and when it looks good you flip the switch: the load balancer or DNS starts sending all traffic to green.

The big advantage is the way back. If something breaks after the switch, you flip traffic back to blue, which is still running the old version untouched. Rolling back takes seconds instead of a frantic redeploy. Once green has proven itself, blue becomes the place where the next release is prepared.

The price is running two copies of everything for a while, and the database is the tricky part: both versions usually share it, so changes to its structure have to work for the old and the new code at the same time. A close cousin is the **canary release**, which moves a small share of users first instead of everyone at once. Cloud tools like AWS CodeDeploy and Kubernetes support both patterns.

## An analogy

A theater with two identical stages. While the audience watches the show on one, the crew sets up the next one on the other; then the seats rotate. If the new set collapses, they rotate back.

## Keep in mind

- Two identical environments: one live, one with the new version.
- Traffic is switched all at once, usually at the load balancer or DNS.
- Rolling back is just switching back.
- Costs double capacity for a while, and database changes need care.

## Go deeper

- [BlueGreenDeployment (Martin Fowler)](https://martinfowler.com/bliki/BlueGreenDeployment.html)
- [Blue/green deployments (AWS whitepaper)](https://docs.aws.amazon.com/whitepapers/latest/overview-deployment-options/bluegreen-deployments.html)
- [Blue–green deployment on Wikipedia](https://en.wikipedia.org/wiki/Blue%E2%80%93green_deployment)

## Related terms

- [Load balancer](https://tidbit.legios.com.ar/load-balancer/): The traffic cop that spreads incoming requests across many servers.
- [DNS](https://tidbit.legios.com.ar/dns/): The internet's phone book: it turns names like wikipedia.org into IP addresses.
- [Rollback](https://tidbit.legios.com.ar/rollback/): Going back to the last version that worked when a new one causes problems.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Canary release](https://tidbit.legios.com.ar/canary-release/): Releasing a new version to a small slice of users first, and widening only if it behaves.
- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Kubernetes](https://tidbit.legios.com.ar/kubernetes/): The system that runs and babysits containers across many machines.
