Saga Design Pattern
-
Saga is a method to do Asynchronous
Distributed Transactions
With 2 Phase Commit we can perform distributed transaction but, those are Blocking/Synchronous.
Read 2 Phase Commit first
Working of Saga
-
Again considering
Customer ordering Pizza
example.
|
Steps 1. Every microservice writes to its DB (local transaction) 2. Publishes an event 3. Other services(consumers) react asynchronously, ie writes to their DBs and publishes event 4. if 1 service is dead, others are not blocked(as in 2 Phase commit) |