liveBook · Manning

Isolation

As explained in Microservices Patterns, Second Edition

A database transaction setting that determines which effects of concurrent transactions may be observed.

Isolation governs how concurrent transactions interact and which changes they can observe. Full isolation makes their outcome equivalent to some serial execution. Databases can relax isolation guarantees to improve throughput, so the isolation level matters when business logic depends on a consistent view of data. section 9.1.1 section 9.3

Queries need isolation even when they do not modify data. Statement-level isolation gives an individual SQL statement a consistent snapshot; transaction-level isolation can give multiple SELECTs a consistent snapshot across the transaction. Without an appropriate guarantee, a query can combine old and new values that never existed together. section 12.1.3

A saga spans multiple local ACID transactions but has no global isolation. Other requests can observe changes between saga steps, and compensation can overwrite a concurrent update. Preventing local anomalies within each service is not enough to prevent anomalies across services. section 9.3 section 9.3.1

Concurrent sagas can produce several anomalies:

  • Lost updates: one saga overwrites another's update without detecting the conflict. section 9.3.1
  • Dirty reads: a transaction or saga reads changes from a saga that has not completed. section 9.3.1
  • Nonrepeatable reads and phantom reads: repeated reads return different values or matching rows after concurrent changes. section 9.3.1
  • Write skew: sagas read overlapping data and update different data in a way that violates a business invariant. section 9.3.1

Concurrent order sagas

A create-order saga creates an order, reserves credit, and schedules delivery; a cancel-order saga cancels the order, releases credit, and cancels delivery. An unlucky interleaving can overwrite the order state and release credit that was never reserved. Another can temporarily increase available credit, allowing an order to succeed when the customer has insufficient credit. section 9.3.1

Use local ACID transactions for operations confined to one service. For sagas, identify shared data and invariants that concurrent steps can affect, then choose application-level countermeasures. Options include semantic locks, commutative updates, and reordering steps to minimize business risk. Sagas reduce runtime coupling compared with classic distributed transactions, but require explicit compensation and careful isolation design. section 9.4 section 9.2.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains isolation levels, query snapshots, saga anomalies, and application-level countermeasures without detailing database concurrency-control internals.
Examples
Illustrates concurrent order creation and cancellation, credit reservation and release, and delivery scheduling.
What you can do after
Evaluate isolation needs and identify saga anomalies and application-level countermeasures.
How it connects
Connects isolation to ACID transactions, sagas, compensating transactions, serialization anomalies, and snapshot isolation.

Also explained in

Compare how 15 books explain 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.