Video in progress
To get events out of a DB, do you use a transactional outbox or direct CDC (Debezium on the tables), and why?
Doing CDC directly on tables exposes your internal DB schema to other teams: every column change breaks them. An outbox (with the Debezium outbox router) gives a clear, versioned event contract. I choose the outbox for public events and table CDC for internal replication and analytics.
📖 Answer
Table CDC: Debezium emits every INSERT/UPDATE/DELETE on the orders table in a before/after form.
You don't touch the code, you can get events even from a legacy system, and nothing is missed. But:
- the events are at the "row changed" level, with no business meaning: the
statuscolumn changed from3to5. Is that "paid" or "cancelled"? - if one business operation changes 4 tables, 4 separate events come out, and the consumer has to reassemble them;
- renaming a column breaks other teams. Your internal schema is now a public API.
Outbox + CDC: the service itself writes an explicit event (OrderPaid, with the fields you need), Debezium watches only the outbox table and, with the EventRouter SMT, sends it to a topic based on aggregate_type, using aggregate_id as the key.
Here the contract is designed on purpose, internal refactoring doesn't affect the outside, and atomicity is one local transaction. The cost: you have to write code, clean up the outbox table, and run the Debezium infrastructure (Kafka Connect, a replication slot).
One operational point with Debezium: the replication slot in PostgreSQL. If the connector is down for a few hours, WAL piles up and fills the DB disk. Monitoring and a max_slot_wal_keep_size limit are a must; I've seen this incident on prod.
The rule I've set for myself: whatever another team reads is a contract, and a contract is written deliberately. Table CDC is good for syncing your own data warehouse, cache or search index, because there the "consumer" who knows the schema is you.
Sign up to mark studied questions and save your progress.