Messaging & Queues interview question · Most asked

What is the dual-write problem and how do you avoid it?

Summary

Writing to a database and publishing to a broker as two separate operations can leave them inconsistent if one fails (order saved but event never sent, or event sent but transaction rolled back). Avoid it with the transactional outbox, change data capture, or by making the broker the source of truth (event sourcing).

Longer Answer

The outbox writes the event in the same DB transaction; a relay publishes it afterwards with at-least-once semantics.

Key Points

  • Two writes, no shared transaction
  • Transactional outbox
  • CDC (Debezium)
  • At-least-once after

More most-asked Messaging & Queues questions

← All Messaging & Queues questions