Backend, APIs & data · Advanced

Schema migrations without downtime

In one line: Change the schema in backward-compatible steps: add, fill, switch, and only at the end — remove.

The problem

During a release, two code versions run together. A migration that changes a column at once breaks one of them. So every structural change is broken into a sequence of steps each safe on its own.

The safe sequence

Add. A new column, nullable, without touching the existing.

Dual write. The code writes to both columns and prefers to read from the old.

Backfill. In small batches, off peak hours, with the ability to stop.

Switch reads. After verifying the data is identical.

Remove. In a separate release, after you've confirmed nobody reads it.

Caution rules

A migration on a large table may lock. Check the locking behaviour in your engine, and run it on a copy sized like production. A backup before, and a written rollback script prepared in advance — not improvised under pressure.

Going deeper

Manage migrations as code in version control, with automated execution and order control. And don't mix a schema change with a logic change in the same release: when something breaks, you want to know which of the two is at fault.