Skip to main content
InterviewHubPRO
Section Overview
Q21

Question 21 of 50

Part 2: Behavioral Patterns & Communication (11 - 24)

42%
Design Patterns (GoF) (50 Qs)•Part 2: Behavioral Patterns & Communication (11 - 24)

What is the Outbox Pattern and how does it guarantee Dual-Write consistency?

junior LevelCode ExampleBehavioral

In Simple Words: When an app must update a database AND publish an event to a message broker (Kafka/RabbitMQ):

  • The Dual-Write Problem: If the database commit succeeds but the network fails before publishing to Kafka, data is out-of-sync!
  • Transactional Outbox Pattern:
    1. App writes entity update AND inserts an event record into an outbox table in the SAME database transaction.
    2. A Change Data Capture (CDC) tool (e.g. Debezium) tails the database transaction log and guarantees publishing the outbox events to Kafka with at-least-once reliability!
text
Transactional Outbox Pattern:
[Application Transaction]
 ├─► UPDATE orders SET status = 'PAID'
 └─► INSERT INTO outbox_table (event_type, payload)
           │ (Single Atomic SQL Transaction!)
           ▼
[Debezium CDC / Poller] ──► Publishes to [Apache Kafka]