Menu

The Dual-Write Problem in Distributed Systems: Implementing the Transactional Outbox Pattern in Node.js & PostgreSQL
📰

The Dual-Write Problem in Distributed Systems: Implementing the Transactional Outbox Pattern in Node.js & PostgreSQL

DEV Community: postgres·subashthiruppathy·3 days ago
#sBL63sKt
#devtopostgresql#devto#dev#order#outbox
Reading 0:00
15s threshold

You've written this code. Everyone has:

async function placeOrder ( input : OrderInput ) { const order = await db . orders . insert ( input ); // 1. write to the database await broker . publish ( ' order.placed ' , { id : order . id }); // 2. tell the rest of the system return order ; }

Enter fullscreen mode

Exit fullscreen mode

It looks correct, and it works for months. Then a deploy lands at the wrong moment, the broker has a hiccup, or the process runs out of memory, and the system quietly ends up in a state that makes no sense:

The order exists, but no email was sent, no inventory reserved, no invoice created

Or the event was published for an order that was rolled back and doesn't exist

There is no exception in your logs, just two systems that disagree.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.