- What is a zero-downtime database migration?
- A migration that runs while the application serves live traffic. Achieved by: making changes backwards-compatible (add columns with defaults, don't drop columns immediately), using the expand-contract pattern, and applying changes in multiple deploys.
- What is the difference between a schema migration and a data migration?
- Schema migration changes the database structure (add/remove columns, change types, add indexes). Data migration moves or transforms actual data (backfill new columns, normalize records, dedup entries). Complex changes require both in a coordinated sequence.
- How do I handle large table migrations (>100M rows)?
- Use batched background jobs rather than a single transaction. Process 1,000-10,000 rows at a time with delays between batches to avoid locking and I/O spikes. Tools like pt-online-schema-change (Percona) and gh-ost (GitHub) automate this for MySQL.