Zero-Downtime Database Migrations: Expand-Contract Playbook
Schema changes are one of the most common sources of deployment incidents. The risky pattern is changing schema and application assumptions in the same release window.
The safer pattern is expand-contract.
Expand phase
Add new columns/tables/indexes in a backward-compatible way. Keep old reads and writes working.
Dual-write and backfill
Temporarily write to old and new schema paths. Run backfill in controlled batches with progress checkpoints.
Read switch
Move reads to the new schema behind a feature flag. Validate latency, error rates, and data consistency before full rollout.
Contract phase
After traffic stabilizes and old path usage drops to zero, remove old columns and code paths in a separate release.
Operational checklist
- Avoid table-wide locks on hot paths.
- Use concurrent index creation where supported.
- Add migration observability (duration, rows/sec, error count).
- Prepare rollback strategy for each phase.
Conclusion
Zero-downtime migrations are not a single SQL script; they are a release sequence. Expand-contract gives teams a repeatable method to evolve schemas without breaking running traffic.
Related posts
Keyset vs Offset Pagination for Large-Scale Datasets
Compares offset and keyset pagination in terms of index strategy, performance, and API experience at scale.
Database per Service vs Shared Database: Data Boundary Design in Microservices
Explores shared database and database-per-service approaches in microservices from technical and organizational perspectives.
Search Index Rebuild Without Downtime
How to rebuild search indexes with zero downtime using blue/green indexes, dual writes, and safe cutover steps.