The saga pattern is used to provide data integrity between multiple services and to do so for potentially long-running transactions. There are many, cursory as they tend to be, blogs written on sagas and long-running transactions. In this piece, I will not go into detail comparing the advantages and disadvantages of sagas with XA two-phase commit (2PC), distributed locking, etc., and will simply state that XA and 2PC require distributed locks (con) which manage ACID properties such that the user can simply execute rollback or commit (pro) whereas sagas use local transactions only and so do not require distributed locks (pro) but require the user to implement compensation, etc. logic (con). As Teddy Roosevelt said, “Nothing worth having comes easy.”

What I will do is show a full code example of a microservices application involving a saga, including participant compensation logic, which can be found at this repo.   

Leave a Reply

Your email address will not be published. Required fields are marked *