The transactional outbox solves the dual-write problem: how to update database AND publish message atomically.
Problem:
Database update succeeds, message publish fails. Data inconsistent.
Solution:
Write business data AND event to outbox table in same transaction
Separate process reads outbox and publishes to message broker
Mark published or delete from outbox
Implementation:
- Polling: Query outbox periodically
- CDC: Debezium streams outbox inserts to Kafka
CDC is preferred for lower latency and preserving commit order.