Loading MQ::STREAM...
“In distributed systems, writing to a database and publishing to a message broker in separate steps is vulnerable to dual-write failure. The Transactional Outbox pattern writes the business state AND an outbox message row in the same ACID database transaction, while a CDC relay (like Debezium) streams outbox rows to the broker.”
Atomically coordinate SQL database mutations with message broker events using Change Data Capture (CDC).
// ACID Transaction with Outbox Table
await db.transaction(async (tx) => {
const order = await tx.orders.create({ userId: 'u_99', total: 250 });
await tx.outbox.create({
aggregateType: 'Order',
aggregateId: order.id,
eventType: 'OrderCreated',
payload: JSON.stringify(order)
});
});
// Debezium captures the outbox INSERT via PostgreSQL WAL replication streamLog-based CDC (reading database WAL write-ahead logs) imposes 0 database lock contention and delivers sub-millisecond relay speeds.