liveBook · Manning

Consistency

As explained in Microservices Patterns, Second Edition

Consistency is the transaction property that a committed transaction leaves the system in a valid state while preserving defined invariants and constraints.

Consistency means that a committed transaction leaves the system in a valid state, preserving defined invariants and constraints. The application logic and constraints executed within the transaction are responsible for preserving them; they must hold at the commit boundary. section 9.1.1

In a saga, local transactions commit separately and the saga lacks ACID isolation. Preserving consistency across its steps therefore requires application-level design techniques. API composition has a related limitation: queries across services lack transactional data consistency and can return mismatched results while updates are in progress. section 9.2 section 12.2.4

BEGIN TRANSACTION

SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ?

UPDATE CONSUMER
  SET AVAILABLE_CREDIT = AVAILABLE_CREDIT - ?
  WHERE CONSUMER_ID = ?
    AND AVAILABLE_CREDIT >= ?

INSERT INTO ORDERS (...) VALUES (...)
COMMIT TRANSACTION

A transaction groups product lookup, credit validation and deduction, and order insertion before commit. section 9.1.1

Figure 12.7 Querying the providers while other system commands are updating the data can result in the provider services returning inconsistent results. In this scenario, the Order is canceled in the Order Service but the Ticket is not yet cancelled in the Kitchen Service.
inconsistent api composition

A query across services can observe an order canceled in one service while its kitchen ticket remains uncanceled in another. section 12.2.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines invariants at the commit boundary and assigns their preservation to application logic and transaction constraints.
Examples
Uses transactional order creation with a credit check and shows mismatched order and ticket status across services.
What you can do after
Evaluate whether transaction boundaries preserve invariants and recognize consistency risks in sagas and cross-service queries.
How it connects
Connects consistency to ACID transactions, sagas, and API composition.

Also explained in

Compare how 28 books explain consistency →

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.