Saga Architecture Pattern

Instead of asking all the participants to commit and then rollback like Two Phase Commit, we follow a sequence flows. So we commit one by one and only rollback if one fails.

Similar to TCC - Try Confirm Cancel but however provide a way to rollback at each step

Pasted image 20230906125453.png

How it works

We can make a Service Wrapper for example and call rollback() function in relevant service if one fails

Pasted image 20230920130001.png

Pros and cons

Pros

  • Easy to implement
  • Minimum locking
  • Retry mechanism

Cons

  • As our service grows, the wrapper can become complex