An order service accepts an order, saves it in PostgreSQL, and publishes an OrderPlaced event to Kafka. Fulfillment depends on that event to begin processing the order. If the service crashes after saving the order but before publishing, the database contains an accepted order that fulfillment never hears about.
The transactional outbox pattern addresses this gap by saving the business change and its outgoing event in the same database transaction. A separate publisher then delivers the saved event to Kafka. Debezium can perform that publication through change data capture, using the database log to find committed outbox inserts.
In this chapter, we'll implement the database side, show how Debezium routes the event, and follow the failure cases that still require careful handling.