Why this matters
- Dual writes to DB and Kafka without an outbox lose messages on crash.
- The outbox is the standard fix for reliable event publishing from BookStore orders.
- Interviewers ask how a relay process reads the outbox without blocking user transactions.
Dual-write problem
L1 · FresherSaving an order and publishing to Kafka in one request can leave inconsistent state if the broker fails after the DB commit.
Outbox table
L2 · IntermediateWrite the event row in the same transaction as the order; a relay process publishes to Kafka asynchronously.
Idempotent consumers
L3 · AdvancedDownstream services must tolerate duplicate deliveries — use event IDs and unique constraints.
Debezium vs polling relay
L4 · ExpertCDC streams outbox changes with low latency; scheduled polling is simpler but adds delay and load on the database.
Hook
When BookStore saves an order it must update inventory and publish OrderPlaced to RabbitMQ. A crash between commit and publish leaves inconsistent state. The transactional outbox writes events in the same DB transaction as the business row.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 7 sections
- Outbox table
- Same transaction as domain write
- Relay process
- BookStore in action
- Runnable BookStore lab
- Failure modes in production
- Ordering and sagas
Test yourself
Answer these before moving on — recall is what makes it stick.