2PC — distributed transaction. Saga — sequence of local transactions.
Two-Phase Commit (2PC):
2PC:
Coordinator → Prepare → Participants
Participants → Vote (Yes/No)
If all Yes → Commit
If any No → Rollback
(Strong consistency, blocking)
Saga Pattern:
Saga:
1. CreateOrder → Success
2. ProcessPayment → Success
3. ShipOrder → Fail → Compensate: RefundPayment, CancelOrder
(Eventual consistency, non-blocking)
Key differences: