What is Eventual Consistency?

Eventual Consistency is a term used when talking about distributed databases. So a distributed database is one where there are several nodes (basically computers) that are responsible for handling database requests from clients (read or write). It often has a leader-follower form, in the sense that one node is a master node and other nodes are slave nodes. The master node receives the requests from the clients and forwards them to the slaves.

When the master node receives a write request from a client (e.g. increment a value/field), then it sends subsequent requests to the salves asking them to update their copy of the value/field and do the increment. Often latency and delay happen due to various reasons (network delay, garbage collection cycle … etc), which means the slaves will process the requests at different times.

This means that if two clients (A,B) will make a read request querying for this particular field, then they might get two different responses, because the master node might direct A’s read request to a node that was done processing the original write request, while B’s request might reach a node that is still processing the write.

This is where eventual consistency comes in. It basically tells the users of the distributed DB system that after some time it guarantees that all slave nodes will have the same value for the field. In other words, eventual consistency is nothing more than a guarantee so that application developers should write their application according to this guarantee.

Why do we have this guarantee? because coordinating writes in distributed DB systems is pretty hard and complex, so DB designers need to introduce consistency abstraction models to help developers know how to write their client applications.

So the next time you need to connect to a distributed DB system and make some read and writes, ask first what kind of consistency guarantee/model does it have. Most of the time it’s just Eventual Consistency.

I learned this concept from the book Designing Data-Intensive Applications in case you are interested in learning more.

Leave a Reply