Engineering Decisions · Senior · Question 5 of 14
An order spans the payment, inventory and shipping services, each with its own database. Any step can fail, and short inconsistency is acceptable. How do you coordinate it?
- 1A saga with compensating actions per step
- 2A two-phase commit across all three databases
- 3One shared database used by all three services
Show the answer
Correct answer: A saga with compensating actions per step
Explanation
A saga runs local transactions and undoes finished steps on failure, which suits services that own their data and accepts brief inconsistency. Two-phase commit fits a few tightly coupled databases that all support it, but it blocks participants and hurts availability. A shared database fits services that aren't really separate, and it brings back the coupling they were split to avoid.