Quick revision
The short answer
Polling on updated_at is cheap to start but misses hard deletes, intermediate updates, rows whose writers forget the column and rows whose transactions commit late. Triggers capture everything in the same transaction but slow every write and need upkeep with each schema change, and dual writes are impossible because we cannot change the code. Log-based CDC, such as Debezium reading the PostgreSQL WAL or the MySQL binlog, captures every committed change in commit order with little load, at the price of database settings, retained logs and schema-change handling, so it is the right choice here.
What to remember
In this answer, we saw that polling by updated_at misses deletes, intermediate updates and late commits and adds load, that triggers are complete but slow the legacy write path and need maintenance, and that dual writes are impossible here and unreliable in general. Log-based CDC reads the WAL or binlog to capture every committed change in order with little load, and its costs are operational: settings, privileges, retained logs and schema changes.
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.
Polling on updated_at is cheap to start but misses hard deletes, intermediate updates, rows whose writers forget the column and rows whose transactions commit late. Triggers capture everything in the same transaction but slow every write and need upkeep with each schema change, and dual writes are impossible because we cannot change the code. Log-based CDC, such as Debezium reading the PostgreSQL WAL or the MySQL binlog, captures every committed change in commit order with little load, at the price of database settings, retained logs and schema-change handling, so it is the right choice here.
Why this question is asked
Feeding a new system from an old database is one of the most common jobs in a modernisation project, and the constraint in this case, that the legacy code cannot be touched, rules out the easiest answer. Interviewers ask this question because each of the four techniques looks fine on a whiteboard and fails in a specific, predictable way in production. In this answer, we will recap what the search service needs from the database, then look at polling, triggers, dual writes and log-based CDC one by one, see exactly what each misses and what it costs, and finish with a comparison and a choice.
1A Quick Recap of What the Search Service Needs
The search service keeps its own copy of the data, an index built for text queries. To stay correct it must hear about every insert, every update and every delete in the legacy database, and it must apply changes to the same row in the order they happened. If it misses a delete, customers find products that no longer exist. If it applies an old update after a newer one, the index shows stale data until the row changes again.
Change data capture, CDC for short, is the general name for turning those database changes into a stream that other systems consume. The four techniques in the question are four ways to get that stream. The legacy application cannot be changed, so anything that needs new application code is out, and anything that loads the legacy database heavily is risky, because that database is still serving the business.
2Polling by an updated_at Column
Polling is the first idea most teams have. A job runs every few seconds, asks for rows changed since the last run, sends them to search, and remembers the newest timestamp it saw, called the watermark.
It looks complete, but it misses several kinds of change. A hard delete removes the row, so there is nothing left to select. If a row changes three times between two polls, we see only its final state, which is fine for a search index but wrong for anyone who needs every step. It relies on every writer setting updated_at, and in a legacy system there is usually a batch script or a manual fix that does not.
The subtle miss is the late commit. A transaction sets updated_at to 10:00:00.5 but commits at 10:00:03. Our poll at 10:00:02 cannot see it yet and moves the watermark to 10:00:02. When the row finally commits, its timestamp is already behind the watermark, so no later poll ever picks it up. Teams patch this by re-reading an overlap window, which adds duplicates and still guesses at how long transactions can take. Finally, polling adds query load, and it needs an index on updated_at that the legacy schema may not have.
3Database Triggers Into a Change Table
A trigger is code the database runs automatically on each insert, update or delete. We can add one without touching the application, and it writes a copy of every change into a change table inside the same transaction.
Because the change row is written in the same transaction, it commits or rolls back with the real change, so deletes and every intermediate update are captured. The cost lands on the legacy database: every write now does a second insert, which adds latency and WAL volume, and the change table must be read and purged by a relay job. The triggers are also code we must maintain. When someone adds a column or renames a table, the trigger has to change with it, and in a legacy system that is easy to forget.
4Dual Writes From the Application
A dual write means the application writes to the database and then also publishes the change, for example to Kafka or straight to search. In our case this is impossible, because we cannot change the application code. It is worth explaining why we would avoid it anyway.
The two writes are not atomic. If the database commit succeeds and the publish fails, or the process crashes between the two, the change is lost for search. If the publish succeeds and the commit rolls back, search shows data that never existed. With two requests updating the same row at the same time, they can commit in one order and publish in the other, so search ends up with the older value. The usual cure is the transactional outbox pattern, which writes the event into a table in the same transaction, and that again needs code changes.
5Log-Based CDC With Debezium
Every relational database keeps a log of committed changes for crash recovery and replication: the write-ahead log (WAL) in PostgreSQL and the binary log (binlog) in MySQL. Log-based CDC reads that log the way a replica would. Debezium is the best-known tool for this; it runs as a Kafka Connect connector and publishes one event per changed row to Kafka.
Notice what we get. Every committed insert, update and delete appears, including deletes and intermediate updates, in commit order, and uncommitted work never appears. The connector only reads the log, so the extra load on the source is small. The application is untouched.
But there is a catch: it brings operational work of its own. We need database privileges and settings, wal_level = logical in PostgreSQL or binlog_format = ROW with a full row image in MySQL. PostgreSQL keeps WAL for a replication slot until the connector confirms it, so a connector that is down for a day can fill the database disk; MySQL instead may purge binlogs the connector still needs. Schema changes have to flow through the pipeline without breaking consumers, and the first load of existing rows needs a snapshot.
6Comparing the Four and Choosing
Putting the four side by side shows why log-based CDC wins for this case: it is the only option that is complete, ordered and needs no change to the legacy code or its write path.
| Technique | Misses | Costs |
|---|---|---|
| Polling on updated_at | Hard deletes, intermediate updates, late commits | Query load, index, overlap logic |
| Triggers | Nothing that commits | Write latency on legacy DB, trigger upkeep |
| Dual writes | Changes when one write fails; order | Code changes (impossible here) |
| Log-based CDC | Nothing that commits | Settings, privileges, log retention, schema handling |
So the choice is log-based CDC, with monitoring on the replication slot or binlog retention from day one, and a Debezium initial snapshot to load the existing products into the index before streaming changes.
7Follow-up questions
Why is CDC alone not a good public event contract for other teams?
CDC events describe rows in tables, so they expose the internal schema of the source database. Every column rename or table split becomes a breaking change for every consumer, and the source team loses the freedom to refactor. Row changes also lack business meaning: an order being placed may be five inserts into three tables, and consumers have to reassemble that. For other teams we publish deliberate domain events, either from an outbox table or by transforming CDC events into a stable, versioned schema owned by the source team, and keep raw CDC topics for internal pipelines.
What happens to the source database if the Debezium connector stops for a day?
In PostgreSQL the replication slot holds its position, so the database keeps every WAL segment written since then. On a busy database that can be hundreds of gigabytes, and if the disk fills, the database stops accepting writes. We alert on retained WAL per slot and can cap it with max_slot_wal_keep_size, accepting that the slot is invalidated and a new snapshot is needed if the cap is hit.
8Conclusion
In this answer, we saw that polling by updated_at misses deletes, intermediate updates and late commits and adds load, that triggers are complete but slow the legacy write path and need maintenance, and that dual writes are impossible here and unreliable in general. Log-based CDC reads the WAL or binlog to capture every committed change in order with little load, and its costs are operational: settings, privileges, retained logs and schema changes.
Open with
Since we cannot change the legacy code, dual writes are out, and they are risky anyway because the database write and the publish are not atomic, so a failure loses or reorders changes.
Then, if they want more
Polling on updated_at is simple, but it never sees hard deletes, it collapses several updates into one, it depends on every writer setting the column, and it can skip a row whose transaction commits after the watermark has moved past its timestamp. It also adds query load.
Triggers writing into a change table are complete, because they run in the same transaction, but they add a second write to every transaction on the legacy database and they have to be maintained with every schema change.
So I would use log-based CDC, for example Debezium reading the PostgreSQL WAL through a logical replication slot or the MySQL row-based binlog. It captures every committed insert, update and delete in commit order with very little load on the source.
The costs are operational: we need wal_level logical or row-based binlog and replication privileges, we must monitor retained WAL so a stopped connector cannot fill the disk, we need an initial snapshot, and we have to plan how schema changes flow to the search service.
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 "Compare polling by an updated_at column, database triggers, dual writes and log-based...": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/e02fce27f7/