Databases & Transactions interview question · Most asked

How do you run schema migrations without downtime?

Summary

Use the expand/contract pattern: first make backward-compatible additions (new nullable columns, new tables), deploy code that writes to both or reads the new shape, backfill data in batches, switch reads, then remove old columns in a later release.

Longer Answer

Avoid long locks: add indexes concurrently (CREATE INDEX CONCURRENTLY), avoid table rewrites on huge tables (adding a column with a volatile default), set lock timeouts, and test migrations against production-sized data.

Key Points

  • Expand → migrate → contract
  • Batched backfills
  • Concurrent index creation
  • Lock timeouts
  • Old and new code must coexist

More most-asked Databases & Transactions questions

← All Databases & Transactions questions