patternMajorpending
Database migration strategy — zero-downtime schema changes
Viewed 0 times
schema migrationzero downtimeexpand contractrolling deploymentbackwards compatible
Problem
Schema changes (adding/removing columns, changing types) require coordinated application and database updates. Rolling deployments mean old and new app versions run simultaneously against the same database.
Solution
Use expand-contract pattern: (1) EXPAND: Add new column/table alongside old one. Both versions work. (2) MIGRATE: Backfill data to new column. Dual-write to both. (3) CONTRACT: Remove old column after all app instances use new schema. Never rename or remove columns in a single deployment. Never add NOT NULL columns without defaults. Use migration tools: Prisma Migrate, Flyway, Alembic, golang-migrate.
Why
During rolling deployments, old app instances still read/write old schema. If you remove a column before all instances are updated, old instances crash.
Revisions (0)
No revisions yet.