Renaming a column sounds trivial — until the application and the database are deployed at different moments. The expand-and-contract pattern makes schema changes safe.
In a system that deploys several times a week, the database and the application never change at exactly the same moment. For a short window, old application code runs against the new schema — or new code runs against the old one. Most migration outages happen in that window.
The expand-and-contract pattern, sometimes called parallel change, removes the window by splitting every breaking change into steps that are each backwards compatible.
The pattern in four steps
- Expand: add the new structure alongside the old one, without removing anything.
- Migrate: deploy code that writes to both, then backfill existing data.
- Switch: deploy code that reads from the new structure only.
- Contract: once nothing uses the old structure, remove it.
Example: renaming a column
Suppose customers.phone needs to become customers.mobile_number. A single RENAME COLUMN would break every running instance of the old code. Instead:
-- Step 1: expand — add the new column (nullable, so no table rewrite)ALTER TABLE customers ADD COLUMN mobile_number text; -- Step 2: backfill in batches to avoid long-running locksUPDATE customersSET mobile_number = phoneWHERE mobile_number IS NULL AND id BETWEEN 1 AND 10000; -- Step 4: contract — only after no code reads or writes "phone"ALTER TABLE customers DROP COLUMN phone;Between those steps, the application writes to both columns and then switches its reads to mobile_number. Every deployment stays safe to roll back, because the previous version of the code still finds the column it expects.
Watch out
Large backfills and index builds can lock tables. Batch your updates, build indexes concurrently where your database supports it, and run heavy steps outside peak hours.
Make it routine
- Review every migration for backwards compatibility before it merges.
- Ship migrations and application changes in separate deployments.
- Automate the check that a contract step only runs after the switch has shipped.
- Rehearse large migrations on a production-sized copy of the data.
Expand and contract adds steps, but each step is small, reversible and boring. In production, boring is exactly what you want.
Written by
Devant Engineering
Product & platform engineering
The engineers who design, build and modernize product platforms — from architecture decisions to release pipelines.




