Two-phase commit (2PC) coordinates a distributed transaction through a prepare phase followed by a commit or rollback phase. It is a traditional way to manage operations spanning services, but its runtime coupling can create availability and latency problems in microservice architectures. section 7.5.1 section 9.1
For operations that cross service boundaries:
- Avoid treating 2PC as the default: its complexity and runtime coupling make it a poor fit for modern microservices, and many modern databases do not support it. section 7.5.1 section 9.4
- Prefer a Saga when implementing distributed system commands; it coordinates local ACID transactions without 2PC’s runtime coupling. section 9.4
Creating an order
A createOrder operation can span the Order and Consumer services: the Order Service persists an order, while the Consumer Service reserves the customer’s credit. This illustrates why a distributed operation crosses independent transaction boundaries. section 7.5.1
Figure 7.8 Services are process and transaction boundaries, so implementing a distributed operation is much more complicated than a local operation that simply spans different classes in different packages.
Use the diagram to see why crossing service and transaction boundaries makes a distributed operation more complicated than a local one. section 7.5.1




