Stairs in Perspective, London.

Eventual Consistency

Mario Mesaglio
2 min readFeb 7, 2020

--

Microservices have changed how distributed architectures are built by providing a framework where value is obtained through adaptation by rapid change. Although plenty of benefits are attained by following the principles behind it, there are implications that one must account for when judging how designs should employ them.

In a time where the available resources are practically endless and almost everything is horizontally scalable, the highly distributed and decentralized aspect of microservices generates a great deal of emergent complexity. Direct messaging between microservices is discouraged, and sharing models and states between them is a recipe for failure.

The Event-Driven Architectures are, therefore, employed to drive asynchronous service communications through events published in an unoriented fashion, de-coupling the publishers from their subscribers and vice-versa. For these reasons, it remains the preferred approach to shape microservice interactions and to decide how they behave in complex distributed transactions.

The story will briefly explain one of the most critical implications of employing event-driven architectures on a microservice ecosystem: Eventual Consistency.

Eventual consistency

Business processes that involve distributed microservices and asynchronous messaging have difficulties maintaining a healthy level of consistency. The individual state of their transactions, as well as the macrostate of the process itself, cannot be realistically determined with ease.

The reason is that immediate collective acknowledgment of all microservices involved in a transaction is only possible by coupling them to one stateful atomic process, like traditional ACID transactions. To do so is not encouraged in microservice architectures. The protocols used to expose capabilities are primarily stateless, like HTTP and interactions between them are driven by asynchronous events, making the task impractical and ineffective.

Based on the assumptions above, when dealing with distributed asynchronous processes, every time the state of a system entity changes, the state of that system is eventually, and not immediately, what it’s expected to be. That is because there might be many state transitions of both global and local nature happening simultaneously.

Hence, there are periods when the system is in an inconsistent state. An observer can only describe its state by aggregating multiple independent microservice states and creating an abstract interpretation.

The concept explained before is known as Eventual Consistency, and it is the consequence of decentralizing master data and driving asynchronous behavior in distributed business processes.

--

--