Scrivio Interview library
ScenarioIntermediate6 min read · updated 13 November 2026

A team exposes its Debezium topics for the internal tables orders and order_items directly to nine other services as its public event stream.

When the team splits order_items into two tables, all nine consumers break, and two of them have been showing half-written orders because they see the orders row before its items. What went wrong, and how would you redesign the published events?

By exposing raw Debezium topics, the team made its internal table design the public contract, so splitting order_items was a breaking change for nine consumers it does not control. CDC also emits one record per row change in a separate topic per table, without the transaction boundary, so consumers can see an orders row before its items. The fix is to publish domain events such as OrderPlaced with its lines, through a transactional outbox captured by Debezium's outbox event router or through a stream processor, keep CDC topics private with ACLs, treat public topics as a versioned API with schema checks, and migrate consumers one by one.

Why this question is asked

Change data capture is a wonderful tool: Debezium reads a database's transaction log and turns every row change into a Kafka record, with no change to application code. That convenience is exactly why teams publish CDC topics directly, and why the problems in this scenario are so common. Interviewers ask it to see whether we understand the difference between an internal data feed and a public event contract. In this answer, we will recap how Debezium CDC works, explain both failures, design the replacement with an outbox, and plan the migration.

1A Quick Recap of Debezium CDC

Debezium is a set of Kafka Connect source connectors. For a database such as PostgreSQL or MySQL, it reads the write-ahead log or binlog, the database's own record of committed changes, and produces one Kafka record for every inserted, updated or deleted row. By default each table gets its own topic, for example shop.public.orders and shop.public.order_items, and each record's value holds the row's before and after state, using the table's column names.

Notice what that means: the shape of the records is the shape of the tables. Column names, types and the way data is split across tables all become visible to anyone who reads the topics.

2Failure 1: The Table Design Became the Contract

Nine services built their logic on the columns of orders and order_items. When the team split order_items into two tables, for example order_lines and line_prices, the old topic stopped receiving changes and two new topics appeared with different fields. Every consumer broke at once.

The owning team did nothing wrong by its own standards; refactoring an internal schema is normal work. The mistake was publishing that schema as the integration contract. Every future refactor, renaming a column, normalising a table, changing a type, is now a cross-team breaking change that needs nine teams to coordinate.

3Failure 2: No Transaction Boundary

Placing an order inserts one row in orders and, say, three rows in order_items in one database transaction. Debezium emits four records into two topics. Within each topic, records are ordered per partition, but there is no ordering between the two topics, and nothing tells a consumer that these four records belong together.

So a consumer can read the orders insert, build an order with zero items, and show it before the items arrive a moment later. That is the half-written order the two consumers displayed. To avoid it, each consumer would have to rebuild the aggregate itself, buffering rows and guessing when the transaction is complete, which is hard to do correctly and is duplicated nine times. Debezium can emit transaction metadata, but using it to reassemble transactions on every consumer is still pushing the producer's job onto its readers.

Step throughOne transaction, two topics, a half-written order
Order DBDebeziumorders topicorder_items topicConsumer
commit: 1 orders row + 3 items rows
orders row 1001
item rows for 1001
poll: order 1001
show order 1001 with 0 items
poll later: 3 items arrive

6 messages in order. Play them, or step through them one at a time.

4Publishing Domain Events Through an Outbox

The replacement is a domain event designed for consumers: OrderPlaced, containing the order id, customer, totals and its lines, in one record, keyed by order id, with a schema the team commits to. The cleanest way to produce it reliably is the transactional outbox. In the same database transaction that writes the orders and items rows, the service inserts a row into an outbox table with the event's type, key and payload. Debezium captures the outbox table, and its outbox event router SMT, io.debezium.transforms.outbox.EventRouter, turns each outbox row into a record on the right topic with the right key.

Java
-- in the same transaction as the business writes
INSERT INTO outbox (id, aggregatetype, aggregateid, type, payload)
VALUES ('9f1c...', 'order', '1001', 'OrderPlaced',
'{"orderId":"1001","lines":[{"sku":"A1","qty":2},{"sku":"B7","qty":1}],"total":"59.90"}');
# Debezium connector, routing outbox rows to public topics (property names: check your Debezium version)
transforms=outbox
transforms.outbox.type=io.debezium.transforms.outbox.EventRouter
transforms.outbox.route.by.field=aggregatetype # -> topic for 'order' events
transforms.outbox.table.field.event.key=aggregateid # record key 1001

Now the database and the events cannot disagree, because both are written in one transaction, and the event is complete when it is published. The internal tables can be refactored freely, as long as the service keeps writing the same OrderPlaced payload. The alternative, when the application cannot change, is a stream processor, for example Kafka Streams or Flink, that joins the raw CDC topics, reassembles orders and publishes the public events; it works but places a fragile mapping between the tables and the contract.

5Keeping CDC Private and Migrating Consumers

The raw CDC topics stay useful inside the team, for example to feed its own search index, but we restrict them with ACLs so only the owning team's principals can read them. The public topic is treated as a versioned API: its schema is registered with BACKWARD or FULL compatibility, checked in CI, documented with an owner, and breaking changes go to a new major version topic.

Migration runs both side by side. We publish the new orders events topic, help consumers move one by one, each switching to OrderPlaced and verifying its results against the old feed, and agree a deadline. When the last consumer has moved, we remove the external ACLs on the CDC topics, which also proves nobody still depends on them.

6Follow-up questions

Is CDC ever fine to expose to other teams?

For analytics and replication into a data lake, where consumers want a faithful copy of tables and accept schema changes, exposing CDC can be reasonable, especially with a clear agreement that the shape follows the tables. For operational services that build business logic on the data, a domain event contract is safer.

Does the outbox table grow forever?

No. Once Debezium has captured a row, it can be deleted; many teams delete outbox rows right after inserting them in the same transaction, because Debezium reads the insert from the log, or run a periodic cleanup. Check how your Debezium version handles deletes so the cleanup does not emit unwanted records.

7Conclusion

In this answer, we saw that raw Debezium topics publish the internal table design as the contract, so a table refactor broke nine consumers, and that CDC emits one record per row change per table without transaction boundaries, so consumers saw orders before their items. Publishing domain events like OrderPlaced with its lines, through a transactional outbox and Debezium's EventRouter SMT or through a stream processor, fixes both. CDC topics stay private behind ACLs, public topics become a versioned API with compatibility checks, and consumers migrate one by one before CDC access is removed.

What to say in the interviewAbout 90 seconds aloud

Open with

Two things went wrong. First, by exposing raw Debezium topics, the team published its internal table design as its public contract. Every column and every table split is visible to consumers, so a normal refactor like splitting order_items became a breaking change for nine services the team does not control.

Then, if they want more

Second, CDC emits one record per row change, in a separate topic per table, without the business transaction boundary. Placing an order writes one orders row and several items rows in one transaction, but consumers read two topics independently, so they can see the order before its items and show half-written orders unless each rebuilds the aggregate itself.

I would redesign by publishing domain events designed for consumers, like OrderPlaced with its lines, keyed by order id. The reliable way is a transactional outbox: the service writes the event into an outbox table in the same transaction, and Debezium captures it with the outbox event router SMT, io.debezium.transforms.outbox.EventRouter.

If the app cannot change, a stream processor can map CDC into public events. I would keep CDC topics private with ACLs and treat the public topic as a versioned API with schema compatibility checks. Then migrate by running both, moving consumers one by one with a deadline, and finally removing their access to the CDC topics.

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 "When the team splits order_items into two tables, all nine consumers break, and two of...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-design/d9fd5bda5a/