- How to update the database and publish a message (event) atomically (either all success, or all fail).
- Cannot use distributed transaction pattens to solve this problem.
- Many modern message brokers don’t support distributed transactions.
- Uses the event table to store the events need to be published.
- Bundles the operation of inserting new record into a business entity table and the operation of inserting a new event to the event table as a single local database transaction.
- Event publisher publishes events by polling the event table periodically.
- The atomicity of updating the database and publishing a message (event) is guaranteed.
- Frequently polling the database can be expensive.
- Tricky to publish events in order.
- Not all NoSQL databases support this pattern.
Topic | Consideration | Possible Solution Options |
---|---|---|
Error handling | The event publisher may publish a event more than once (For example, crash after publishing an event but before marking the corresponding event record as published). |
- Book: Chris R.(2018). Chapter 3. Interprocess communication in a microservice architecture, Microservices Patterns (pp. 65-109). Manning Publications
- Book: Kasun I., Prabath S.(2018). Chapter 5: Data Management, Microservices for the Enterprise (pp. 125-150). Apress
- Web Article: Pattern: Transactional outbox | https://microservices.io/patterns/data/transactional-outbox.html
- Web Article: Event-Driven Data Management for Microservices | https://www.nginx.com/blog/event-driven-data-management-microservices/