A release needs to rename a column that the running app reads and writes. How do you do it with zero downtime?

IntermediateScenarioData and databases
Answer

Situation read → During a rolling deploy, old and new versions run together. A plain rename breaks whichever version doesn't know the new name. Use expand and contract.

What I'd do →

  1. Expand: add the new column (nullable), deploy code that writes to both and reads the old.
ALTER TABLE users ADD COLUMN email_address text;
  1. Backfill in small batches to avoid long locks:
UPDATE users SET email_address = email WHERE id BETWEEN 1 AND 10000 AND email_address IS NULL;
  1. Switch reads to the new column in the next release (still writing both).
  2. Contract: stop writing the old column, and a release or two later drop it.

Why → Each step is backward compatible, so you can roll back the app at any point without a data fix.

Interview tip → Say "the database change must be compatible with both the old and new app version"; that's the core rule.

All Real-World Interview questions Roadmap: Interview readiness

More on Data and databases