Quick revision
The short answer
Debezium writes the change to a topic named <topic.prefix>.<schema>.<table>, such as shop.public.orders, with a key holding the primary key, {"id": 1001}. The value is an envelope with before, after, source (connector, database, table, LSN, transaction id, commit time), op (c, u, d or r) and ts_ms. A DELETE produces an event with op d and after null, followed by a tombstone; before holds only the primary key because PostgreSQL logs only the old key unless the table uses REPLICA IDENTITY FULL.
What to remember
In this answer, we saw that Debezium writes each table to <topic.prefix>.<schema>.<table>, keys records by the primary key so each row's changes stay in order on one partition, and wraps each change in an envelope with before, after, source, op and ts_ms. A delete produces an op d event followed by a tombstone for compaction, controlled by tombstones.on.delete. And before usually holds only the key on PostgreSQL, because the default replica identity logs only the old key; REPLICA IDENTITY FULL logs the whole old row at the cost of more WAL.
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.
Debezium writes the change to a topic named <topic.prefix>.<schema>.<table>, such as shop.public.orders, with a key holding the primary key, {"id": 1001}. The value is an envelope with before, after, source (connector, database, table, LSN, transaction id, commit time), op (c, u, d or r) and ts_ms. A DELETE produces an event with op d and after null, followed by a tombstone; before holds only the primary key because PostgreSQL logs only the old key unless the table uses REPLICA IDENTITY FULL.
Why this question is asked
Change data capture with Debezium turns every committed row change in a database into a Kafka record, and almost every consumer of CDC data has to understand the shape of those records to use them correctly. Interviewers ask this concept question because misreading the envelope causes real bugs: consumers that ignore deletes, treat snapshot reads as inserts, or expect the full old row and get only a key. In this answer, we will look at the topic and key Debezium uses, walk through the value envelope field by field, see what a delete produces, and explain why before is often incomplete on PostgreSQL.
1The Topic and the Key
By default, Debezium writes each captured table to its own topic named from three parts: the connector's topic.prefix, the schema and the table. With topic.prefix=shop, changes to public.orders go to shop.public.orders. Routing transforms can change this, but one topic per table is the default.
The record key is a struct of the table's primary key columns, here {"id": 1001}. This is a deliberate choice. Kafka sends all records with the same key to the same partition, and a partition keeps order, so every change to order 1001 arrives in the order the database committed it. Consumers can then apply changes per row without worrying that an older update overtakes a newer one.
2The Value Envelope
The value is an envelope that describes the change rather than just the new row. Here is the UPDATE of row 1001, shown as JSON without the schema part.
| op | Meaning | before / after |
|---|---|---|
| c | insert (create) | null / new row |
| u | update | old row or key only / new row |
| d | delete | old row or key only / null |
| r | read during a snapshot | null / current row |
after is the row as it is now. before is the row as it was, when the database provides it. source describes where the change came from: the connector, database, schema and table, the position in the write-ahead log (lsn), the transaction id, and source.ts_ms, the time the change was committed in the database. op says what kind of change it was, and the top-level ts_ms is when Debezium processed the event. The gap between source.ts_ms and ts_ms is a quick measure of capture lag. Recent Debezium versions also add microsecond and nanosecond variants of these timestamps; check your version.
3What a DELETE Produces
A delete produces two records with the same key. The first is a normal change event with op d, before set (to the old row or at least its key) and after null, so consumers can see what was deleted. The second is a tombstone: the same key with a null value.
The tombstone exists for log compaction. A compacted topic keeps only the latest record per key, and a null value tells Kafka it may remove the key entirely after a while. Without it, a compacted CDC topic would keep the delete event for row 1001 forever. The connector setting tombstones.on.delete, true by default, controls whether the tombstone is sent.
4Why before Contains Only the Key
Debezium does not query the table to find the old row; it reads the write-ahead log, the WAL, which PostgreSQL writes for every change. For updates and deletes, what PostgreSQL puts in the WAL about the old row is controlled by the table's replica identity. Under the default replica identity, PostgreSQL writes no old values for an update that keeps the key, and only the old key columns for a delete or a key change. So before is either just the key, as in our example, or empty, and the exact rendering can vary by Debezium version; what it never has is the full old row.
If consumers need the full old row, for example to compute what changed or to audit old values, we set the table's replica identity to FULL.
The cost is more WAL: every update now logs the full old row as well as the new one, which increases disk writes, replication traffic and the work Debezium does. For wide or busy tables that can be significant, so we enable it only where someone needs the old values.
5Follow-up questions
What does the ExtractNewRecordState transform do to this envelope?
It unwraps the envelope so the record value becomes just the after state, a plain row, which is what most sinks and simple consumers want. Options control what happens to deletes, for example passing the tombstone through, dropping it, or rewriting the delete as a row with a __deleted field, and can copy fields such as op or source.ts_ms into the row. The option names have changed across Debezium versions, so check the documentation for yours.
Why is the key the primary key and not the order id from the application?
Debezium only knows the table's structure, and the primary key is what identifies a row. If the table has no primary key, the key is null unless we configure message.key.columns, and then changes to one row can land in different partitions and lose their order.
How should a consumer treat op r events?
As upserts by key. They are rows read during a snapshot, which may arrive after or interleaved with live changes, so a consumer that treats them as inserts may fail on duplicates or overwrite newer data.
6Conclusion
In this answer, we saw that Debezium writes each table to <topic.prefix>.<schema>.<table>, keys records by the primary key so each row's changes stay in order on one partition, and wraps each change in an envelope with before, after, source, op and ts_ms. A delete produces an op d event followed by a tombstone for compaction, controlled by tombstones.on.delete. And before usually holds only the key on PostgreSQL, because the default replica identity logs only the old key; REPLICA IDENTITY FULL logs the whole old row at the cost of more WAL.
Open with
Debezium writes the change to a topic named topic prefix, schema, table, so with topic.prefix=shop it goes to shop.public.orders, one topic per table by default. The key is a struct of the primary key columns, here id 1001, which means every change to that row lands on the same partition and stays in commit order.
Then, if they want more
The value is an envelope. before is the row before the change, after is the row after. source describes the origin: the connector, database, schema and table, the LSN in the write-ahead log, the transaction id, and source.ts_ms, the commit time in the database. op is c for insert, u for update, d for delete and r for a row read during a snapshot.
The top-level ts_ms is when Debezium processed the event.
For a DELETE, Debezium sends an event with op d, before set and after null, and then a tombstone, the same key with a null value, so log compaction can remove the key; tombstones.on.delete controls that. before often holds only the primary key because PostgreSQL writes only the old key to the WAL for updates and deletes under the default replica identity.
If consumers need the old row I would set REPLICA IDENTITY FULL on the table, accepting more WAL.
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 documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
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 "Describe the Kafka record it produces: topic name, key, and the fields of the value...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/105d591457/