← Lessons

quiz vs the machine

Platinum1860

System Design

Blue Green Database Changes

Running two database environments so you can switch and roll back with confidence.

5 min read · advanced · beat Platinum to climb

Two environments

A blue green deployment keeps two environments, blue and green. One serves live traffic while the other is prepared with the new version. You cut traffic over to the new one and, if something goes wrong, cut back. For stateless services this is clean.

Databases are harder

Databases hold state, so you cannot just spin up a fresh green copy and switch. Writes that land on green during the cutover must not be lost, and you need a way back if you roll back.

  • Keep one shared database and make the schema compatible with both blue and green code using expand and contract.
  • Or replicate continuously from the blue database to a green one and switch the write target, accepting a careful cutover.

The safe path

In practice most teams favor a shared backward compatible database so the only thing that flips is the application tier. That keeps the rollback as simple as routing traffic back, with no data to reconcile.

Key idea

Blue green works cleanly for stateless tiers, but databases hold state, so the safe pattern is a shared backward compatible schema where only the application flips and rollback is just rerouting traffic.

Check yourself

Answer to earn rating on the learn ladder.

1. Why are databases harder to blue green than stateless services?

2. What is the safest common approach for blue green with a database?