Distributed transactions: the strict way and the practical way.
Two-Phase Commit and Sagas: distributed transactions
choose the failure mode you can explain
Sagas are eventually consistent; intermediate states are visible.
Two-phase commit (2PC) coordinates a transaction across multiple services with a prepare-and-commit handshake. It's correct, but if the coordinator fails, participants can block forever. Sagas avoid coordinators by chaining local transactions with compensating actions.
2PC: coordinator asks all to PREPARE; if all yes, COMMIT; else ABORT. If coordinator dies after PREPARE, participants are stuck holding locks.
Sagas: do local transaction in service A, then B, then C. If C fails, undo B then undo A via compensations. No global locks.
Choreographed sagas: events trigger steps. Orchestrated sagas: a workflow engine coordinates steps. Both are common.
Booking flow: charge card, reserve seat, send confirmation.