Transaction management preserves consistency when operations read or change data. A local operation can use an ACID database transaction that commits on success and rolls back on failure; an operation spanning services crosses separate transactional boundaries. section 7.5.1 section 9.1
In a microservice architecture, services collaborate through APIs and may use separate databases, so a conventional database transaction cannot manage the whole operation. Classic XA/2PC is a poor fit; the Saga pattern is the preferred approach for distributed system commands. section 9.1 section 9.0
Transaction management also matters for system queries, which need isolation even though they do not update data:
- Statement-level isolation gives a SQL statement a consistent snapshot, preventing it from seeing another transaction’s uncommitted changes. section 12.1.3
- Transaction-level isolation gives multiple SELECT statements in one query a consistent snapshot. Isolation levels may be relaxed for higher throughput; Oracle and PostgreSQL provide snapshot isolation for short-lived read-only transactions. section 12.1.3
A distributed order
The local createConsumer() operation can run in one ACID transaction. By contrast, createOrder() invokes Customer Service to reserve credit, crossing service boundaries and complicating transaction management. section 7.5.1
Figure 7.9 Distributed transactions are replaced with a sequence of local transactions coordinated by asynchronous messaging
Shows distributed transactions replaced by a sequence of local transactions coordinated through asynchronous messaging. section 7.5.1
