How does the transactional outbox pattern solve the dual-write problem?
Reviewed by Gurusankar M.
Short Answer
The dual-write problem: you can't atomically update your DB AND publish to a broker — a crash between them leaves them inconsistent. The outbox pattern writes the event into an 'outbox' table in the SAME local transaction as the data change; a separate relay (or CDC like Debezium) then reliably publishes those rows to the broker.
On this page
Concept Made Simple
Coffee Chat Question
“How does the transactional outbox pattern solve the dual-write problem?”
Remember It Faster
Mind Map Answer
- Dual write
- DB + broker can't be atomic → drift
- Outbox
- event row in same DB txn as the change
- Relay/CDC
- publishes outbox rows to the broker
- Result
- no lost or phantom events
Think Beyond the Expected
What If?
Why not just publish to Kafka right after the DB commit succeeds?
If the process crashes after the commit but before the publish, the data changed but no event was sent — a lost event (or, if you publish first then the DB write fails, a phantom event). The outbox makes the event part of the same atomic DB transaction, so it can't be lost; the relay guarantees at-least-once publish.
Real World
Transactional outbox (often with Debezium CDC reading the table's log) is the standard reliable way to publish domain events from a service without losing them on crashes — paired with idempotent consumers.
Interviewer's Expectation
Keywords they're listening for:
- dual-write inconsistency
- outbox row in same txn
- relay/CDC publishes
- at-least-once → idempotent consumers
- Debezium
Common Mistakes
- Publishing to broker outside the DB transaction
- Assuming exactly-once (it's at-least-once + dedup)
- No cleanup of published outbox rows
Best Practices
- Write events to an outbox in the same txn
- Relay via CDC; consumers dedupe idempotently
- Prune/Archive published outbox rows
Follow-up Questions
- How does CDC (Debezium) read the outbox?
- Why do consumers still need to be idempotent?
- Outbox vs listen-to-yourself patterns?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Sagas & Events (Microservices) Interview question: "How does the transactional outbox pattern solve the dual-write problem?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair