Yordis Prieto Logo

Outbox Pattern

When you need to save data and publish an event atomically, write both to the database in one transaction and let a relay handle the broker. Read the full blog post for the story behind the pattern.

ServiceDatabaseBrokerConsumerWrite to databasePublish to broker1INSERT order2OK3publish(OrderPlaced)4ack5poll6deliver(OrderPlaced)7ack

Write to database

1Service saves the order to the database.
2Database confirms the write.

Publish to broker

3Service publishes the event to the broker.
4Broker acknowledges the event.
5Consumer polls the broker for new events.
6Broker delivers the event to the consumer.
7Consumer acknowledges processing.

Found an issue or have an improvement? Drop me an email