Staying Online
A naive migration locks tables and stops traffic. Zero downtime migration evolves the schema in small backward compatible steps so the application keeps serving while the change rolls out.
The Expand Contract Pattern
The core technique is expand and contract, also called parallel change.
- Expand: add the new column or table without removing the old one.
- Migrate code to write to both old and new shapes and backfill existing rows.
- Contract: once everything reads the new shape, drop the old one.
Each step is independently deployable, and at no point does the running code depend on a shape that does not exist yet.
Why Compatibility Matters
During a rollout, old and new application versions run at the same time. Every intermediate schema must satisfy both. A change that is not backward compatible, like renaming a column in one step, would break the older running code and cause errors.
Key idea
Zero downtime migration uses expand and contract steps that stay backward compatible, so old and new code coexist and the application never goes offline.