Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the WAIT command provide strong consistency in Redis?

Greetings overflowers,

In Redis sentinel/cluster setup, can we use the WAIT command with the total number of slaves to ensure strong consistency across the Redis servers? Why not?

Kind regards

like image 590
geeko Avatar asked Nov 10 '15 11:11

geeko


Video Answer


1 Answers

WAIT implements synchronous replication for Redis. Synchronous replication is required but not sufficient in order to achieve strong consistency. Strong consistency is practically the sum of two things:

  1. Synchronous replication to the majority of nodes on a distributed system.
  2. A way to orchestrate change of leadership (failover basically) so that it is guaranteed that only a node preserving the full history of acknowledged operations in the previous leader can be elected.

WAIT does not provide "2". The replication process in Redis is performed by Sentinel or Redis Cluster, and is not able to provide property 2 (since the synchronous replication in Redis is the exception not the rule, so there was no much focus on that aspect). However what Redis replication does is to attempt to promote the slave that appears to preserve the greatest amount of data. While this does not change the theoretical guarantees of Redis failover, that can still lose acknowledged writes, it means that if you use WAIT, there are more slaves having a given operation into their memory, and in turn it is a lot more likely that in the event of a failover, the operation will be retained. However while this will make a failure mode that discards the acknowledged operation hard to trigger, there always exists a failure mode with this properties.

TLDR: WAIT does not make Redis linearizable, what it does is to make sure the specified number of slaves will receive the write, that in turn makes failover more robust, but without any hard guarantee.

like image 153
antirez Avatar answered Oct 05 '22 19:10

antirez