Skip to main content
PreparationZone Logo
PrepZone

Transactional Outbox Pattern (Deep Dive)

Atomically save the order and the outbox row — then relay to Kafka without dual-write races.

Pass checkpoint below

Why this matters

  • VaultCommerce order INSERT and outbox INSERT commit atomically in Postgres.
  • Relay polls outbox with FOR UPDATE SKIP LOCKED — horizontal scale without duplicate publish.
  • At-least-once relay means consumers still need idempotency.
  • Industry standard before reaching for Kafka transactions alone.
@TransactionalOrder + outbox row
Outbox relay
Kafka topic
Save business row and outbox row in one DB transaction. Relay process publishes to Kafka asynchronously.

Outbox table design

Columns: id, aggregate_type, aggregate_id, event_type, payload (JSON/Avro bytes), created_at, published_at. Index on (published_at) WHERE published_at IS NULL. VaultCommerce relay batches 100 rows per tick.

Key points

  • Outbox table — staging events in OLTP alongside business rows
  • Relay — process that reads outbox and publishes to Kafka
  • Same transaction — business write + outbox insert atomic
  • SKIP LOCKED — concurrent relay workers without row contention
  • Debezium outbox event router — CDC-based relay from outbox table

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 · 2 sections

  • Relay implementation
  • VaultCommerce rollout checklist

Test yourself

Answer these before moving on — recall is what makes it stick.