How do you rename a column used by a live service with zero downtime?

Short answer

Use the expand-and-contract pattern: add the new column, deploy code that writes both and reads the new one with fallback, backfill existing data in batches, switch reads fully, stop writing the old column, and finally drop it in a later release, keeping each step backward compatible so rolling deployments and rollbacks work.

Detailed answer

  1. Expand: ALTER TABLE ADD COLUMN customer_ref (non-blocking; avoid defaults that rewrite tables on old engines).
  2. Deploy v2: dual-write old and new; read new, fall back to old.
  3. Backfill in batches with throttling; verify counts.
  4. Deploy v3: read/write only new.
  5. Contract: drop old column after a safe period (separate migration).

Use online schema tools (gh-ost, pt-online-schema-change) for large MySQL tables; CREATE INDEX CONCURRENTLY in PostgreSQL.

What the interviewer expects

Step-by-step backward-compatible migration and awareness of locking.

Common mistakes to avoid

A single migration that renames the column while old pods still run.