Never as a single update statement. Add the column as nullable with no default rewrite, then backfill in small batches ordered by primary key, committing each batch, with a short sleep between them and a check on replication lag. Make the job resumable by recording progress, run it off peak, and have the application write the new column for new and updated rows so the backfill only has to catch history.
Why interviewers ask this
This is an operational question dressed as a data task, and it is very easy to fail. One giant update can hold locks, bloat the write ahead log, blow out replication lag and take the site down. The interviewer wants batching, throttling based on a live signal, resumability, and the double write strategy that lets you switch over safely. It also shows whether you plan the verification step.
How to structure your answer
- Explain why one big update is dangerous: locks, bloat, replication lag.
- Describe the batched, resumable job and its throttle signal.
- Have the application write the new value going forward.
- Define verification and the cutover to reading the new column.
Example answer
One update touching two hundred million rows holds locks, generates an enormous amount of write ahead log, and pushes replicas so far behind that reads start serving stale data, so the site suffers even though nothing crashed. Instead I add the column as nullable, which is cheap on a modern Postgres because it does not rewrite the table, and I deploy the application change that populates it on every insert and update first. That means the backfill only has to handle history, and history is not moving. Then the job walks the primary key in batches of a few thousand, commits each batch, records the last id it finished so it can resume after a restart, and pauses if replication lag or database load crosses a threshold. I run it with a rate limit rather than as fast as possible. When it finishes I verify with counts and spot checks that nothing is left null, then flip reads to the new column behind a flag, and only after that add the not null constraint, validated separately so it does not take a long lock.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you add a not null constraint without a long lock?
- What signal do you throttle on, and what threshold?
- How do you verify the backfill was correct, not just complete?
Related backend developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions