Skip to main content
Back to Blog
25 June 20248 min read

Database Migration Strategies: Zero-Downtime Schema Changes

DatabaseMigrationDevOpsArchitecture

Techniques for evolving database schemas without service interruption. Expand-contract pattern, feature flags, and blue-green database deployments.


Database Migration Strategies: Zero-Downtime Schema Changes

Schema changes shouldn't require downtime. Here's how to evolve databases safely.

The Expand-Contract Pattern

  1. Add new column/table (expand)
  2. Migrate data and update application
  3. Remove old column/table (contract)

This approach allows rollback at each stage.

Online Schema Changes

For large tables, use online schema change tools like pt-online-schema-change (MySQL) or pg_repack (PostgreSQL).

Feature Flags for Data Changes

New code paths can read from old and new schemas simultaneously. Feature flags control the switch, enabling gradual rollout and instant rollback.

Testing Migrations

  • Always test on production-like data volumes
  • Measure migration time on realistic datasets
  • Plan for rollback scenarios
  • Run migrations in staging first

Share this article