← Lessons

quiz vs the machine

Gold1380

Databases

Zero Downtime Migration

Evolving schema and data without taking the application offline.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the expand step do?

2. Why must each intermediate schema be backward compatible?

3. When is it safe to perform the contract step?