What is the dual-write problem?
The dual-write problem happens when a system needs to save a business change to a database and publish a message about that change to notify other services, and treats these as two separate, independent operations. Because they're two operations against two different systems, one can succeed while the other fails — most commonly, the database save commits successfully but the subsequent message publish fails due to a network issue or a crash at the wrong moment. The result is a change that's safely recorded but that nobody else in the system ever learns about, since the notification was lost. A classic real-world symptom is an order that exists in a database while the warehouse was never notified to ship it. Simply moving the publish call earlier or wrapping it in a try-catch doesn't fix the underlying issue, since the two operations remain fundamentally unable to succeed or fail together.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response