liveBook · Manning

Blue-green deployment

As explained in Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform

A blue-green deployment is a release pattern that maintains separate old and new infrastructure environments and switches service traffic between them.

Blue-green deployment creates a new green subset of infrastructure, tests it separately, gradually shifts traffic from the existing blue environment, and then removes blue. It favors immutable resources, isolates change, and reduces the blast radius of risky infrastructure updates. section 9.2 section 9.2.6

Apply the pattern as an ordered infrastructure change:

  • Copy the blue configuration into a green version, changing only the attributes required for the update. section 9.2.1
  • Deploy the changed low-level resource, then recreate the high-level resources that depend on it. section 9.2.2
  • Test the green infrastructure and its applications before exposing live requests. section 9.2
  • Send a small percentage of traffic to green, verify requests and regression behavior, and increase the share over time. section 9.2 section 9.4
  • Switch production traffic fully to green and remove the old blue resources after validation. section 9.2

Use blue-green deployment when reverting is slow or uncertain, dependencies are difficult to identify, or downtime would affect critical applications. It costs more temporarily because two environments exist, especially for low-level resources such as networks, projects, or accounts. section 9.2.6

Migrating a database

When a database cannot safely change networks in place, create a green database, migrate and reconcile data from blue, switch applications to the new endpoint, and remove blue. Stateful resources require this migration step because replacement can corrupt or lose data. section 9.3.1 section 9.4

Figure 9.5 Use blue-green deployment to create a green environment for the global network, send some traffic to the new resources, and remove the old resources.

Trace the deployment flow from creating green global infrastructure through partial traffic, validation, full cutover, and removal of blue. section 9.2

How Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform covers it

How deep it goes
Explains configuration, dependent resources, traffic shifting, testing, migration, and cleanup, while deferring detailed rollback practices.
Examples
Uses global networks, clusters, premium-networked servers, databases, load balancers, Python IaC, and separate tool-state folders.
What it assumes
Assumes infrastructure-as-code, dependency management, traffic routing, testing, and data migration practices.
What you can do after
Operate/configure staged infrastructure changes, progressively route traffic, migrate stateful resources, and limit failed updates.
How it connects
Connects infrastructure as code, immutable infrastructure, canary deployment, stateful infrastructure, active-passive configurations, and rolling upgrades.

Also explained in

Compare how 5 books explain blue-green deployment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform. The section links point to the parts of the book it draws on.