liveBook · Manning

Transaction management

As explained in Microservices Patterns, Second Edition

Transaction management is the coordination of transactional operations to preserve the required consistency and completion semantics of data changes.

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
2PC BASE

Shows distributed transactions replaced by a sequence of local transactions coordinated through asynchronous messaging. section 7.5.1

How Microservices Patterns, Second Edition covers it

How deep it goes
Distinguishes local ACID transactions, distributed transaction constraints, and query isolation levels, then points to sagas without detailing their implementation.
Examples
Contrasts createConsumer() with createOrder() and explains query snapshots through SQL SELECT statements.
What you can do after
Evaluate why local transaction mechanisms do not span services and why sagas suit distributed commands.
How it connects
Connects ACID transactions, microservices, the Saga pattern, asynchronous messaging, and database isolation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.