Reputation: 99
For example I have Master(M) and Slave1(S1) and Slave2(S2). If I do synchronous replication as below,
But the above is not strong consistency.
The users reading Slave1 or Slave2 can get different values at certain moment.
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.
Upvotes: 4
Views: 5127
Reputation: 6860
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.
Upvotes: 4