DEV Community

Cover image for Consistency models

Consistency models

Nicola Apicella on November 05, 2017

Consistency models Why this post? I have found somehow difficult to find an authoritative source which describes what is the ...
Collapse
 
bgadrian profile image
Adrian B.G.

I had a hard time to understand why should I read the article after the first part, I think an intro would be good,what are distributed systems,who makes them, who uses this patterns with real examples.
I think I understood the patterns but not why they exists, where can I use them etc.

Collapse
 
napicella profile image
Nicola Apicella

Hi! thanks for the feedback.
I changed a bit the introduction based on your input.
The article is not supposed to be an introduction to distributed systems, instead it aims to document a specific aspect of such systems, which are consistency models.

Collapse
 
qeesung profile image
η§¦δΈ–ζˆ

Can Sequential consistency see out of date data?

Collapse
 
napicella profile image
Nicola Apicella

No, under sequential consistency each processor(or node) observes the same history of operations. This means that each node is gonna read fresh state. (Fresh here means that the read operations read the last write. Note that the info might become outdated right after)

Collapse
 
qeesung profile image
η§¦δΈ–ζˆ

Thank you very much for your quick reply. Each processor(or node) observes the same history of operations, maybe the client read the stale data from different processor, for example, a client writes a variable x=0 through process 1, and then writes a variable y=0, and process 1 propagate these events to the process 2, If the client initiates a read operation before the event reaches process 2, will it read the outdated data?

Thread Thread
 
napicella profile image
Nicola Apicella • Edited

U re welcome :)
what you described in your example cannot happen under sequential consistency.
The model is an abstract contract of the behaviour the system must respect at any point in time.
Coming back to your example you, just to make it a bit more concrete, we could:

  • use sessions for clients, so that reads and writes for the same client end up to the same processor
  • or use a leader processor which serializes reads and writes to other nodes. The idea is similar to what Raft and Paxos do.

Both these approaches will cause the clients to observe a system which behaves as sequential consistent.

Thread Thread
 
qeesung profile image
η§¦δΈ–ζˆ

Thank you very much. Your answer has solved my doubts. : -)

Thread Thread
 
napicella profile image
Nicola Apicella

Glad it helped :)

Collapse
 
govardhangdg profile image
Govardhan G D

Hello! Loved the post! I was wondering about how to implement sequential consistency in a system that can accept write requests from multiple processes simultaneously, like multi leader replication system? Thanks.

Collapse
 
napicella profile image
Nicola Apicella

Hi, thanks. What do you want to build?
Depending on the system and the database you plan to use, some sort of session affinity could be enough to guarantee sequential consistency. Session affinity in this context means that all the reads/writes coming from one process are going to be executed by the same node in the order in which they were issued.
Anyway, I do not have all the info you have - without that it is hard for me to give a more concrete answer.

Collapse
 
harinath001 profile image
Harinath Kanchu

you mentioned about "casual consistency", is it supposed to be "causal consistency" ?

Collapse
 
napicella profile image
Nicola Apicella

Yes, it s a typo. Thanks for reporting it