loading...
Cover image for Eventual Consistency and Strong Consistency
Nlogn

Eventual Consistency and Strong Consistency

mayankjoshi profile image mayank joshi Updated on ใƒป2 min read

System Design (6 Part Series)

1) What Are Load Balancers And How Load Balancing Is Done? 2) Horizontal Scaling And Vertical Scaling 3 ... 4 3) Consistent Hashing - System Design 4) What is CAP theorem and where is it used? 5) Eventual Consistency and Strong Consistency 6) A Guide To Ace Your Next System Design Interview ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

Before discussing the difference between Eventual & Strong Consistency, let's first understand consistency in distributed systems.

A consistent distributed systems are those in which all nodes see the same data at the same time. In other words, if we perform read operations after multiple write operations then a consistent system should return the same value for all the read operations and that too the value of the most recent write operation.

To understand this concept properly, I highly recommend reading about CAP Theorem.

Eventual Consistency

Eventual consistency guarantees that if an update is made to the data of a node (say node N), then the updated value will eventually be propagated to all the replicas of that node and eventually all the replica will become consistent to the original node(N). Nodes will get eventually consistent means it will take time for updates to reach other replicas.

Hence eventual consistency is a consistency model used to achieve high availability and is a weak consistency model.

Nodes that have achieved eventual consistency is often said to have converged, or achievedย replica convergence.

Eventual Consistency

Eventual consistency offers high availability(low latency) at the risk of returning stale data.

The most popular system that implements eventual consistency is DNS (Domain Name System). Updates to a domain name are distributed according to a configured pattern and in combination with time-controlled caches; eventually, all clients will become consistent or see the update.

Strong Consistency

In contrast to eventual consistency, Strong consistency guarantee that if an update is made to a node (say N), then the updated value will be propagated to all the replicas(N1 & N2) of the node(N), immediately in other words after the update completes, any subsequent access (to N, N1, or N2) will always return the updated value.

Note during the time these replicas are being updated with new data, any read/write request to any of these replicas will get delayed as all replicas are busy in keeping each other consistent and once they will become consistent with the original node they will start accepting read/write request again.

As opposed to eventual consistency in strong consistency, always only one consistent state will be observed.

Strong Consistency

Eventual consistency offers low availability(high latency) but always returns fresh/updated data.

The most popular system that implements eventual consistency is relational databases. This means in relational database data viewed immediately after an update will be the same for all observers.

Further Reading
  1. CAP Theorem
  2. Database Shardingย 

System Design (6 Part Series)

1) What Are Load Balancers And How Load Balancing Is Done? 2) Horizontal Scaling And Vertical Scaling 3 ... 4 3) Consistent Hashing - System Design 4) What is CAP theorem and where is it used? 5) Eventual Consistency and Strong Consistency 6) A Guide To Ace Your Next System Design Interview ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

Posted on May 22 by:

mayankjoshi profile

mayank joshi

@mayankjoshi

I love system design and most of the time I find myself learning or designing one of them. I'm highly active on twitter, So ping me there.

Nlogn

nlogn is a Computer Science portal specially designed to help you prepare for product-based companies interviews by practicing a wide variety of problem-related to system Desing, Data-Structure and much more.

Discussion

markdown guide