Sending Reliable Event Notifications with Transactional Outbox Pattern
Friends don’t let friends do dual writes!
Although the Microservices maintain their state private to them, they hardly operate in isolation. Some business use cases require them to change their state first, then notify that change to a broader audience.
The Transactional Outbox pattern describes an approach for services to execute these two tasks atomically.
In this post, I discuss why dual writes in distributed systems are bad, how you can fix that with the outbox pattern, and some inner workings of the pattern. This post doesn’t stand up as an implementation guide but instead brings in the fundamentals you should use when implementing in production.
The problem with dual writes
Imagine there are two microservices; the Order service and the Shipping service. The business logic states the Order service should notify the Shipping service about a new order reception to prepare a shipment.
What are the options we have here?
Synchronous approach: The Order service synchronously invokes an API method of the Shipping service to do the notification. The drawback is that it introduces a coupling between two services. The Order service…