liveBook · Manning

Eventual consistency

As explained in Microservices Patterns, Second Edition

A consistency model in which a multi-service operation is completed through separate transactions whose effects converge over time rather than immediately satisfying a single ACID transaction.

Eventual consistency handles operations that span services and therefore cannot use a single database transaction. Instead, the operation proceeds through a series of local transactions, with their effects converging over time rather than taking effect atomically. section 1.3.4 section 7.5.1

A local operation can execute within one transaction. A distributed operation crosses process and transaction boundaries, so its local transactions must be coordinated; asynchronous messaging is one way to do this. The application may also need explicit undo logic and concurrency handling rather than relying on the database to manage them. section 1.3.4 section 7.5.1

Figure 7.9 Distributed transactions are replaced with a sequence of local transactions coordinated by asynchronous messaging
2PC BASE

The figure shows a distributed transaction replaced by local transactions coordinated through asynchronous messaging. section 7.5.1

Creating an order across services

A createOrder() operation that spans services cannot be implemented as one database transaction. It must instead use transactions within the participating services, with the added work of coordinating them and handling concurrency or undo when necessary. section 1.3.4

Use service boundaries deliberately. Keeping performance-critical operations within one service can avoid distributed-operation costs, although it may require larger services. Some operations will still span services, so account for network latency, runtime coupling, and the complexity of eventual consistency when evaluating the design. section 1.3.4 section 7.5.1

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines a series of local transactions and identifies coordination, undo, and concurrency concerns without specifying an implementation procedure.
Examples
Uses a createOrder() operation spanning services to illustrate the transaction boundary problem.
What you can do after
Evaluate when a distributed operation requires eventual consistency and weigh its complexity against keeping an operation local.
How it connects
Connects local transactions with asynchronous messaging, concurrency handling, runtime coupling, and service boundaries.

Also explained in

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