Interview Prep/SRE & Reliability/Release Engineering & Reliability Patterns

What is the expand/contract (parallel change) pattern for database migrations?

AdvancedConceptRelease Engineering & Reliability Patterns
Answer

Split breaking schema changes into backward-compatible steps:

  1. Expand: add the new column or table; old code ignores it.
  2. Deploy code that writes to both old and new, and backfill existing rows.
  3. Deploy code that reads from the new.
  4. Contract: stop writing the old column, then drop it in a later release.

At every step the previous code version still works, so any deploy can be rolled back safely.

All SRE & Reliability questions

More on Release Engineering & Reliability Patterns