What does two-phase commit cost in latency, availability and throughput, and why do many systems avoid it across services?
Sketch your own answer first, then compare it with the one below.
A strong answer
Latency: two round trips plus forced log writes at each participant and at the coordinator, and the transaction is as slow as its slowest participant.
Availability: the transaction commits only if every participant is up. With n participants each up with probability a, it commits with probability about a to the n. Add the blocking when the coordinator fails, and the locks of in-doubt transactions stall other work.
Throughput: locks are held through both rounds, so hot rows serialize.
Teams avoid it between independent services because those services do not share a transaction manager and should not lock each other. They use sagas or design to keep a transaction inside one partition instead. It remains common inside one database, where the participants are replicas or shards that the same system manages.
Sources
- Pat Helland (2007). Life beyond Distributed Transactions: an Apostate's Opinion.
- Philip A. Bernstein, Vassos Hadzilacos, Nathan Goodman (1987). Concurrency Control and Recovery in Database Systems.
- Jim Gray, Leslie Lamport (2006). Consensus on Transaction Commit.