Create a strategy for zero-downtime database migrations

Instruction: Outline a strategy for performing database migrations with zero downtime, ensuring continuous availability of the application.

Context: This question challenges the candidate to devise strategies for database migrations that avoid service interruptions, critical for high-availability systems.

Updated

Official answer

Treat zero downtime as a service objective to demonstrate, not a guarantee from a migration pattern. Identify lock/rewrite behavior, data volume, old/new application compatibility, peak load and acceptable abort thresholds for the actual engine.

For a schema change, expand with compatible fields or tables, deploy readers/writers that tolerate both versions, backfill in bounded resumable batches, verify parity, switch reads, and only later remove the old contract. A feature flag controls code paths; it does not make incompatible data compatible.

For movement to another database, establish a consistent snapshot plus ordered change capture with a known handoff boundary. Preserve inserts, updates and deletes, and prevent an older backfill row from replacing a newer change. Two independent writes can diverge when only one succeeds; use a durable coordination/replay design and reconciliation instead of assuming “double-write” is atomic.

Before cutover, compare keyed content and invariants, measure lag, drain or fence old writers, and verify the authoritative destination. A rollback after new-only writes requires reverse synchronization or another explicit repair path. Restoring old code does not recover lost columns or transfer those writes back.

Rehearse realistic volume, concurrent traffic, failure and restart. Monitor user errors, lock waits, latency, replication lag and reconciliation failures throughout. Delay destructive cleanup until dependencies and recovery requirements permit it, and state any unavoidable interruption rather than promise seamless migration in every scenario.

Related Questions