SeniorDatabases

How do you run a schema migration with zero downtime?

What they are really testing: Senior signal: knows the expand/contract (parallel change) pattern, backward-compatible changes, and avoiding long locks, rather than ALTER-and-pray during a deploy.

A real interview question

How do you run a schema migration with zero downtime?

What most people say

drag me

I would run the ALTER TABLE during a low-traffic window so few users are affected.

A maintenance window is downtime, and a big ALTER can lock the table and break the running app. Zero downtime needs the expand/contract pattern with backward-compatible steps and a deploy strategy, not a quiet-hours ALTER.

The follow-ups they ask next

  • Why can you not just rename a column in one migration?

    During a rolling deploy, old code still references the old name and would break the moment you rename. Instead: add the new column, write to both, backfill, switch reads, then drop the old one, expand/contract across separate deploys.

  • What kinds of schema operations are dangerous because of locking?

    Ones that take a long exclusive lock or rewrite the table, some ALTERs, adding a NOT NULL with a default on older engines, adding an index without the concurrent/online option. Use online DDL and batched backfills so traffic is never blocked.

What the interviewer is listening for

  • Knows expand/contract (parallel change)
  • Backward-compatible steps for rolling deploys
  • Avoids long locks / batches backfills

What sinks the answer

  • Maintenance-window ALTER as the answer
  • Renames/drops in one step
  • Unaware of table-locking operations

If you genuinely do not know

Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.

Zero-downtime needs [backward-compatible changes, since old and new code run together during a rolling deploy]. Use [expand/contract: add the new column/table, write to both, backfill in batches, switch reads, then later drop the old]. [Avoid long-locking operations (some ALTERs, NOT NULL+default on old engines), use online DDL and batched backfills]. Not [an ALTER in a maintenance window].

Keep going with databases

All 336 cloud engineer questions

Knowing the answer is not the same as recalling it under pressure

Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.

Start free