Definition: The Outbox Pattern solves the problem of reliably updating a database and publishing an event/message.
The service stores the business change and an “outbox event” in the same database transaction, then a separate process publishes the event.
Without Outbox
Update DB ✅
Publish Kafka message ❌
Now the database changed but nobody knows about it.
With Outbox
DB transaction:
Update Order
Insert Outbox Event
↓
Commit ✅
↓
Outbox Publisher
↓
Kafka
Examples:
- Create order +
OrderCreatedevent. - Register user +
UserRegisteredevent. - Change payment status +
PaymentCompletedevent.