Today I learned about the Outbox Pattern.
The Outbox Pattern solves a common problem. Consider a system that charges a payment, processes an order, and then sends an email.
The payment, order-processing, and email-sending all happen in a database transaction— if any of them fails, we roll back. A question: when the payment and order succeed, do we wait for the email to send before deciding that the transaction succeeded? What it the email-sending fails; do we roll back the payment and order?
A solution is the Outbox Pattern. Instead of sending the email in the transaction, we record the email message in an outbox table. A separate process then publishes that message with the necessary retries and idempotency.
This explains how a user can order an item even when, say, the email sending code fails or the email provider is offline. They aren’t coupled in real time anymore.