← Back to Blog

Zero-Downtime Database Migrations in Containerized SaaS Apps

The expand-and-contract pattern for schema migrations alongside fractional canary container releases.

By Database Infrastructure Team
1 min read
Zero-Downtime Database Migrations in Containerized SaaS Apps

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:

Zero-Downtime Database Migration Pipeline

The 3 Stages of Backward-Compatible Migrations:

  1. 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.
  2. Migrate & Sync: Dual-write or asynchronously sync data to the new schema format.
  3. 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