Menu

The transactional outbox pattern in Node.js: never lose an event when the database commits
📰

The transactional outbox pattern in Node.js: never lose an event when the database commits

DEV Community: database·Ali Ahmed·about 14 hours ago
#CzKMTRvC
#devtodatabase#devto#dev#event#outbox
Long article (1046 words) — no AI summary yet.
Reading 0:00
15s threshold

When a service updates its database and then publishes an event (to a queue, a webhook or another service), there's a gap between the two. If the process crashes after the commit, or the broker is down, the change is saved but the event is lost ; publish first instead, and a failed commit leaves an event about something that never happened. The transactional outbox closes the gap: write the change and the event row into an outbox table in the same database transaction , so both are saved or neither is. A separate relay reads the outbox and publishes each event, retrying until it succeeds. Delivery becomes at least once , so consumers must be idempotent . Here's a tested Node.js implementation with the built-in node:sqlite , and an ordering bug worth knowing about.

Why can't you just publish after committing?

In a KYC pipeline, approving a verification has to tell other systems: unlock the account, email the customer, notify compliance.…

Continue reading — create a free account

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