The Dual-Write Problem & Outbox Pattern
The Dual-Write Problem & Outbox Pattern
HardBackend0% accepted
Your service writes an order to Postgres and then publishes an 'order.created' event to Kafka. Sometimes the DB commit succeeds but the publish fails (or vice-versa), leaving systems inconsistent. Explain the dual-write problem and how the transactional outbox pattern solves it.
Approach
You can't atomically write to a DB and a queue. Write the event to an 'outbox' table in the SAME transaction as the order; a separate relay reads the outbox and publishes, guaranteeing at-least-once delivery.
More Backend problems
Browse all coding problems →Scenarios & Expected Answers
No example scenarios for this problem.
Sign in to continue
Create a free account to view answers and mark progress.
- Free forever — no credit card
- Theory Q&A with detailed answers
- Points, streaks & leaderboards