Zero-Downtime Database Migrations in Containerized SaaS Apps
The expand-and-contract pattern for schema migrations alongside fractional canary container releases.
Deploying application updates is only half the battle. If your deployment includes breaking database schema changes, rolling back a failed release can become a nightmare.
To achieve true zero-downtime deployments, your application and database schema must be backward-compatible throughout the rollout process.
The Expand-and-Contract Pattern
SafeDeployer recommends using the Expand-and-Contract (or Parallel Change) design pattern when running database migrations alongside canary releases:

The 3 Stages of Backward-Compatible Migrations:
- Expand: Add new tables or columns without removing old ones. Both the legacy version (v1.0) and canary version (v2.0) continue to operate safely.
- Migrate & Sync: Dual-write or asynchronously sync data to the new schema format.
- Contract: Once 100% of traffic is successfully shifted to v2.0 and verified, deprecate and remove legacy columns.
By decoupling database migrations from code deployment, your canary rollouts remain 100% safe and instantly reversible at any phase!
Discussion