Saga
A saga is a sequence of local transactions. Each one updates its own database and publishes a message or event that triggers the next. If one fails because it breaks a business rule, the saga runs compensating transactions that undo what the earlier ones did. It's like planning a trip step by step: you book the flight, then the hotel, then the car; if the car fails, you cancel the hotel and the flight.
The difference from 2PC is that in a saga each step commits right away in its own database, without waiting for the others. There's no global 'everyone ready'. That's why it doesn't block: each service carries on. The cost is that, for a while, some steps are done and others aren't. It's like a relay race: each runner runs their leg and passes the baton, without waiting for everyone to be on the track.
Sagas have problems. They're hard to debug, because the flow is spread over several services. There can be cyclic dependencies between participants. Since there's no isolation between them, others can see data halfway through, which complicates durability. And testing is hard, because every service must be running to simulate a transaction. It's like debugging an email chain among 6 people.
2PC and sagas solve the same problem in opposite ways. 2PC locks everyone until everyone is ready: consistent but blocking. A saga lets each step commit alone and fixes things with compensations if something fails: no blocking, but there's an inconsistent window. It's like paying as a group: either everyone waits until all cards are out (2PC), or each pays their share and accounts are settled later (saga).
