Skip to main content
PreparationZone Logo
PrepZone

Transactional Outbox

Publish events reliably after DB commits using the outbox table pattern.

Pass checkpoint below

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 · Fresher

Saving an order and publishing to Kafka in one request can leave inconsistent state if the broker fails after the DB commit.

Outbox table

L2 · Intermediate

Write the event row in the same transaction as the order; a relay process publishes to Kafka asynchronously.

Idempotent consumers

L3 · Advanced

Downstream services must tolerate duplicate deliveries — use event IDs and unique constraints.

Debezium vs polling relay

L4 · Expert

CDC streams outbox changes with low latency; scheduled polling is simpler but adds delay and load on the database.

@Transactional service
orders + outbox tables
Relay / @Scheduled poller
Kafka topic
Write business row and outbox row in one DB transaction; relay publishes asynchronously.

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.