Quick revision
The short answer
A bulk UPDATE is a flood for log-based CDC: every changed row becomes an event that every downstream consumer must process, so the plan has to cover CDC capacity, not only database capacity. The migration should have run in throttled batches while watching consumer lag, with changes consumers do not need filtered out or loaded into the targets directly. To recover, we scale consumers to the partition count, raise sink batch sizes, prioritise live changes, and for search consider rebuilding the index from the database and switching an alias instead of replaying 300 million events.
What to remember
In this answer, we saw that a bulk UPDATE turns into one CDC event per row for every consumer, so a migration must be planned against downstream capacity, measured as events per consumer and drain time. We throttle backfills in small, resumable batches driven by consumer lag, filter or bypass changes consumers do not need, and recover by scaling consumers, batching harder, flushing caches and rebuilding the search index with an alias switch. A checklist item with an events-per-table estimate makes the check routine.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A bulk UPDATE is a flood for log-based CDC: every changed row becomes an event that every downstream consumer must process, so the plan has to cover CDC capacity, not only database capacity. The migration should have run in throttled batches while watching consumer lag, with changes consumers do not need filtered out or loaded into the targets directly. To recover, we scale consumers to the partition count, raise sink batch sizes, prioritise live changes, and for search consider rebuilding the index from the database and switching an alias instead of replaying 300 million events.
Why this question is asked
Schema migrations are usually reviewed for one risk: will the database cope? This incident shows a second, quieter risk. The database finished the UPDATE in an evening, but the pipelines downstream of it fell six hours behind, and customers saw stale orders all night. Interviewers ask this to see whether we think of a database as part of a data system rather than an island. In this answer, we will see why a backfill turns into a change flood, what the plan should have contained, how to throttle and filter a backfill, how to recover tonight, and how to make the check routine.
1Why a Backfill Becomes a Change Flood
Log-based CDC reads the database log, and the log does not know the difference between a customer placing an order and a migration rewriting a column. An UPDATE of 300 million rows writes 300 million row changes into the WAL or binlog, and Debezium faithfully turns each into a Kafka event carrying the full row.
Now multiply. If the search indexer handles about 15,000 events per second, 300 million events take 300,000,000 / 15,000 = 20,000 seconds, about five and a half hours, which matches the six hours of lag we saw. Every other consumer, the cache invalidator and the warehouse loader, has to chew through the same 300 million events at its own speed. Worse, live changes from real customers are queued behind the backfill in the same partitions, so a price change made at 21:00 reaches search after 03:00.
2What the Plan Should Have Contained
The migration review checked locks and runtime on the database. It should also have estimated events per consumer: rows touched, multiplied by the number of CDC consumers, divided by each consumer's throughput. That number tells us how long downstream systems will be behind, and whether that is acceptable.
| Consumer | Throughput | Time to drain |
|---|---|---|
| Search indexer | 15,000 events/s | about 5.6 hours |
| Cache invalidator | 60,000 events/s | about 1.4 hours |
| Warehouse loader | 100,000 events/s | about 50 minutes |
Seen this way, the slowest consumer sets the damage, and the plan must answer three questions before anyone runs the UPDATE: can the backfill be slowed so live changes keep flowing, do consumers need these changes at all, and if they do, is there a cheaper path than the event stream?
3Running the Update in Throttled Batches
Instead of one statement, we update a slice of rows at a time and pause between slices. The pause gives consumers time to catch up, so the live changes in between are only seconds behind instead of hours.
Notice that the throttle is driven by consumer lag, not by database load. The database could take far more, but the point is to keep the slowest consumer within its freshness target. The loop is also resumable: if it stops halfway, the WHERE region_code IS NULL condition makes a rerun skip rows already done. Small transactions also mean the CDC connector never has to buffer one gigantic transaction.
4Keeping Unneeded Changes Away From Consumers
Often a consumer does not care about the new column at all. If the search index does not contain region_code, all 300 million events are pure waste for it. There are a few ways to avoid that work. A consumer can compare the changed columns and skip events where nothing it indexes changed; this needs the before image of the row, which in PostgreSQL means REPLICA IDENTITY FULL on the table, so check the cost first. A Debezium transform such as a filter can drop matching events before they reach the topic (check what your connector version supports).
When consumers do need the new value, the backfill does not have to travel through the live stream. We can write the backfill to a separate topic that consumers read at low priority, or load the targets directly in bulk: a bulk indexing job for search and a single table load for the warehouse, while CDC continues to carry only live changes.
5Recovering Tonight
We are already six hours behind, so the priority is to get live data fresh again. First, scale each consumer group up to the number of partitions; consumers beyond the partition count sit idle, so that is the ceiling. Next, raise batch sizes in the sinks, for example larger Elasticsearch bulk requests and larger JDBC batches, since a backlog is exactly when batching pays. Caches can simply be flushed or given short TTLs so they reload from the database, which is already correct.
For search, replaying 300 million events may be the slowest option. Often it is faster to build a fresh index directly from the database with a bulk job, then switch the index alias to it. To avoid losing changes made during the rebuild, we record the CDC position when the rebuild starts and point the indexer at the new index from that position.
- Record current CDC positionthe point the new index must catch up from
- Bulk-build a new index from the databaseorders_v2, parallel readers, large bulk requests
- Replay CDC from the recorded positiononly the few hours of live changes
- Switch the alias to orders_v2readers move in one atomic step
- Delete the old indexafter a short observation period
5 steps in order. Play them, or step through them one at a time.
Rebuilding beats replaying when the backlog is far larger than the table's live change rate.
6Making It a Checklist Item
The lasting fix is a line in the migration review template: for each table touched, the estimated number of rows changed, the CDC consumers of that table, and the expected drain time for each. Any migration above a threshold, say ten million rows, needs a throttling plan or a bypass path, and the consumer owners are told in advance with the expected timing. This turns a surprise outage into a planned, slower migration.
7Follow-up questions
How would you warn downstream teams before a large migration?
I would make the CDC topology visible, so the migration author can see every consumer of the table from a catalog instead of guessing. Then the warning is specific: table, estimated number of events, the planned window and pace, and whether the changes will carry fields they use. Consumer owners confirm they can absorb it or ask for a bypass, and someone watches lag dashboards during the run with the authority to pause the backfill.
Why not just skip consumers to the latest offset?
Skipping throws away the live changes that are mixed in with the backfill events, so search would miss real price and status changes. It is only safe if we then rebuild the target from the database, which is the alias switch approach with extra steps.
Would one big transaction have been better than many small ones?
No. The log still holds 300 million row changes, and Debezium has to process one huge transaction at once, which can exhaust memory and blocks every later change until it is done. Small batches spread the same work out so live changes can slip in between.
8Conclusion
In this answer, we saw that a bulk UPDATE turns into one CDC event per row for every consumer, so a migration must be planned against downstream capacity, measured as events per consumer and drain time. We throttle backfills in small, resumable batches driven by consumer lag, filter or bypass changes consumers do not need, and recover by scaling consumers, batching harder, flushing caches and rebuilding the search index with an alias switch. A checklist item with an events-per-table estimate makes the check routine.
Open with
The core problem is that log-based CDC turns a bulk update into a change flood. 300 million rows became 300 million events, and every consumer, search, caches and the warehouse, had to process each one, with live customer changes stuck behind them in the same partitions.
Then, if they want more
Before the migration, I would have estimated drain time per consumer, rows changed divided by each consumer's throughput, and run the update in throttled batches of about 10,000 rows, pausing whenever the search indexer's lag passed something like 30 seconds, so live changes stayed fresh.
If consumers did not need region_code, I would filter those events or have consumers skip changes that touch no field they use, and if they did need it, I would load the targets directly in bulk or through a separate topic.
To recover now, I scale consumer groups up to the partition count, increase bulk sizes in the sinks and flush caches so they reload from the database. For search, I would probably build a fresh index from the database, replay CDC only from the position recorded at the start, and switch the alias, which beats replaying 300 million events.
Then I add CDC impact, with an events-per-table estimate, to the migration review checklist.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What should have been planned before the migration, and how do you recover now?": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/41c2d27b80/