Menu

1 / 5

The Transactional Outbox Pattern, With a Node.js Example

DEV Community: postgres·Muhammad Azlaan Zubair·23 minutes ago
#pHAEENcd
#devtopostgresql#devto#dev#event#order
Reading 0:00
15s threshold

The transactional outbox pattern makes a business change and its event record part of the same database transaction. A separate relay publishes committed outbox rows and retries failures. This closes the gap created when an application commits a database write and publishes a message as two independent operations.

This guide implements the pattern with PostgreSQL 18, Node.js 26 LTS, and the pg\ driver . The relay sends events to a small HTTP consumer so the example can run without assuming a specific broker's delivery guarantees. The same outbox can feed a broker through a publisher adapter or a change-data-capture (CDC) pipeline.

The dual-write problem

Imagine an order service that saves an order and then publishes order.created :

await db . query ( " INSERT INTO orders ... " ); await broker . publish ( " order.created " , event );

Enter fullscreen mode

Exit fullscreen mode

There are two independent systems involved: the database and the event transport.…

Continue reading — create a free account

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