Automating Database Schema Migrations Safely in Continuous Delivery
Eliminate downtime during relational database schema changes using the expand and contract pattern, migration locking, and zero-downtime column alterations.
CloudPlatformLabs Engineering
Platform Architecture Team
1. The Expand and Contract Pattern
Never execute breaking schema changes (e.g. renaming or deleting a column) in a single deployment. Because old and new application versions run concurrently during zero-downtime rolling updates, the old version will immediately crash if a required column is renamed.
Follow the three-phase Expand and Contract pattern:
Phase 1 (Expand): Add the new column as nullable and update application code to write to both columns and read from the old.
Phase 2 (Backfill): Backfill existing data from the old column into the new column in batched background transactions.
Phase 3 (Contract): Switch application reads to the new column, deprecate the old column, and safely drop the old column in a subsequent release.
2. Safe Migration Automation in Kubernetes
Run database migrations in isolated Kubernetes Jobs with Helm pre-install/pre-upgrade hooks before newly deployed web pods start up, ensuring transactions commit cleanly before traffic shifts.
Related Topics & Tags
Written by CloudPlatformLabs Engineering
Platform Architecture Team
CloudPlatformLabs publishes independent, peer-reviewed cloud and DevOps architecture blueprints, hands-on tutorials, and infrastructure case studies. Our mission is to make advanced infrastructure engineering transparent, resilient, and developer-friendly.