In a typical e-commerce scenario, a user places an order. The system does these two things:

  1. Insert the order into database (1st write operation)
  2. Send a notification to downstream systems such as payment service, fulfillment services, etc. (2nd write operation)

One of problems is that what if the system fails after inserting the order. Another one could be what if the notification fails. If you check the SLAs of building blocks, most offer 99.5% to 99.99% availability. These kinds of problems do happen in modern clouds.

Transactional Outbox Pattern is one of patterns resolving the dual write operations problem mentioned in the typical e-commerce scenario. The solution [1,3] is to:

  1. Replace the second write operation with an Outbox. Outbox is usually a database table in the same database for the 1st write operation. The 3rd party system such as Lambda can process the records asynchronously
  2. Wrap 1st write and 2nd write operation into one transaction

One of implementations of Outbox [1, 3] can be DynamoDB. This is interesting because it takes advantage of DynamoDB stream, an item-level event notification.

So when can we apply this pattern?

  1. Use it in a cause-effect relationship, and the effect end can be processed asynchronously
  2. Use it in two or more write operations as long as there is a chain of cause-effect relationship.

I would like to point out this pattern might also reduce the probability of deadlocks and increase performance

For more details, please refer to links below. Link #3 is an easy-to-follow walk-through. Highly recommend trying this.

References:

  1. https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/transactional-outbox.html
  2. https://microservices.io/patterns/data/transactional-outbox.html
  3. https://aws.amazon.com/blogs/compute/implementing-the-transactional-outbox-pattern-with-amazon-eventbridge-pipes/