Why is two-phase commit (2PC) problematic in microservices?
Answer
Two-phase commit (2PC) is a distributed transaction protocol that coordinates multiple participants to either all commit or all rollback a transaction. It requires a coordinator that first sends a "prepare" request to all participants (phase 1) and then, if all agree, a "commit" (phase 2). In microservices, 2PC is problematic for several reasons: it creates tight coupling between services and the coordinator, it is blocking — participants hold locks during the protocol, reducing throughput significantly, the coordinator is a single point of failure, and it does not work across heterogeneous databases (SQL + NoSQL). The recommended alternative is the Saga pattern with compensating transactions, which achieves eventual consistency without distributed locking.
Previous
What is the Transactional Outbox pattern?
Next
What features does a service mesh like Istio provide?
More Microservices Architecture Questions
View all →- Intermediate What is event-driven architecture and how does it apply to microservices?
- Intermediate What is the Saga pattern in microservices?
- Intermediate What is CQRS (Command Query Responsibility Segregation)?
- Intermediate What is event sourcing in microservices?
- Intermediate What is the Circuit Breaker pattern?