Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain strong consistency in distributed computing?

For example I have Master(M) and Slave1(S1) and Slave2(S2). If I do synchronous replication as below,

  1. Update Master, and lock the write
  2. replicate Slave1 and Slave2
  3. unlock the write of Master.

But the above is not strong consistency.

  • Scenario 1, when both replicates for S1 and S2 are successful,

The users reading Slave1 or Slave2 can get different values at certain moment.

  • Scenario 2, replicate S1 successful, but replicate to S2 fails.

In this case, Master should cancel the write to S1. But users may already read it.


So it's hard to maintain strong consistency. Therefore, what algorithms do companies use to maintain strong consistency if it's necessary? How to make the eventual write value be visible to clients at the exact same time? Thanks.

like image 473
user1130800 Avatar asked Oct 27 '25 08:10

user1130800


1 Answers

Putting things in the simplest form;

There are two ways to provide consistency

  • First is to take the lock before writing anything to the database or caching system. This ensures read and write lock. This includes master server as well.

    To further enhance the locking mechanism, the distribution of keys is maintained as such so the reads are always re-directed towards the consistent server(s) (if new servers are also being added at that time).

    At this time of lock, operations can also be buffered (with timeouts) so when the new value is applied. that is returned.

  • Secondly, if replication fails then there is the added complex layer of rollovers. This ensures that data is consistent if not then it is not applied.
like image 112
Basit Anwer Avatar answered Oct 29 '25 05:10

Basit Anwer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!