liveBook · Manning

Stateful infrastructure

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

A stateful infrastructure resource is an infrastructure component that persistently stores or manages application data across operations and replacements.

Stateful infrastructure comprises resources that store or manage data, including databases, queues, caches, and stream-processing tools. Changes require extra care because replacing or updating a resource can corrupt or lose application data. section 9.3.1 section 9.4

Use a blue-green change process when updating a stateful resource in place is unsafe or unsupported:

  • Duplicate the infrastructure configuration and create a green resource. section 9.3.1
  • Migrate and reconcile data from blue to green, then test the new resource before switching applications. section 9.3.1 section 9.3.2
  • Switch application traffic or endpoints to green and remove blue only after applications no longer depend on it. section 9.3.1 section 9.3.3
  • Make migration automation idempotent so repeated runs produce the same state without duplicating data. section 9.3.2

Incremental database cutover

A canary-style rollout can first write to both databases, then write exclusively to green, and finally read from green. Regression testing at each stage enables rollback to blue, although dual writes may require data-reconciliation automation. section 9.3.3

Figure 9.10 If you can’t update the database in place, you must deploy a new green database, migrate and reconcile the data, and change the database endpoint from blue to green.

Follow the deployment sequence for creating green, migrating and reconciling data, and changing the database endpoint. section 9.3.1

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

How deep it goes
Explains resource types, blue-green sequencing, idempotent migration, testing, cutover, and cleanup without detailing resource-specific migration procedures.
Examples
Uses databases, queues, caches, stream-processing tools, blue-green environments, migration pipelines, and staged application reads and writes.
What it assumes
Assumes familiarity with infrastructure as code and deployment changes while teaching the data-protection concerns of stateful resources.
What you can do after
Operate/configure blue-green and canary changes while migrating data, testing functionality, preserving idempotency, and delaying removal of the old resource.
How it connects
Connects stateful infrastructure to blue-green deployment, canary deployment, infrastructure as code, data migration, and deployment pipelines.

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.