The outbox pattern

You cannot commit a row and publish a message together. So you write the message as a row.

The dual write, the outbox row, and the relay that publishes it (interactive map)

One POST /orders writing the order row and the message it will send on the same connection, in the same transaction, so a crash has no gap to land in. Below it sits the dual write it replaces, where committing first leaves the broker never told about SO-4417 and the commit standing anyway. To the right, the two ways the row gets out, a poller claiming it with SKIP LOCKED or a tailer reading it from the write-ahead log, and then the consumer, which is where the duplicate a relay can produce has to stop.

← All cheatsheets