You are building an online travel booking system. A customer books a flight, a hotel, and a rental car â three separate services, three separate databases. Either all three reservations succeed, or none should, because a flight without a hotel is a problem.
In a single database this would be a transaction: the database guarantees atomicity. But across services, there is no shared transaction log. You need a protocol.
Two main strategies exist. Two-Phase Commit (2PC) holds a global lock â every participant votes, then either everyone commits or everyone aborts. It is atomic but blocking: a coordinator crash mid-protocol can freeze all participants for minutes or longer. Sagas take the opposite approach: each step executes immediately and publishes an event. If a later step fails, earlier steps are compensated â undone by explicit reversal actions. The final state is only eventually consistent, but no service is ever blocked waiting for a lock.
The choice between 2PC and sagas is not a detail â it is one of the most consequential design decisions in distributed systems.
Comments
Loading comments...