Skip to main content
← Back to articles

Zero-Downtime Database Migrations

Expand/contract migrations, backfills, and feature flags that keep services online during schema change.

Nestlancer Editorial

Share

Zero-Downtime Database Migrations

Schema changes are production incidents waiting to happen unless you use expand/contract phases and feature flags that decouple deploy from DDL.

Expand/contract rhythm

  1. Expand: add nullable column or new table
  2. Migrate: dual-write or backfill job with idempotent batches
  3. Switch: application reads new column behind flag
  4. Contract: drop old column after traffic fully cut over

Never rename in place—add new, migrate, delete old.

Backfill safely

-- Batch updates avoid long locks
UPDATE users SET display_name = full_name
WHERE id IN (SELECT id FROM users WHERE display_name IS NULL LIMIT 5000);

Run during low traffic; monitor replication lag on replicas.

Feature flag coordination

  • Flag off: old schema path only
  • Flag on for internal staff: validate new path
  • Gradual percentage rollout with error rate dashboard
  • Flag removal only after contract column dropped

Prisma migration hygiene

Squash only in dev. Production migrations stay incremental and reversible for one release.

Zero-downtime migrations are a collaboration between app and DBA—ship code that tolerates both schemas during the transition window.

Comments

Loading comments…

Related posts