redisnosqlhigh-availabilitykey-value-storeconsistency

Redis availability and CAP theorem


In CAP theorem, Redis is specified as a database which lacks availability (which has partition tolerance and consistency).

But there are many places where Redis is considered as a high availability key-value store.

CAP theorem and DBMS

What is right? I would be thankful if you could provide an in-depth answer.


Solution

  • I would start by saying that there is no 'CA' category. Most systems are CA in absence of Network Partition.

    CAP theorem is applicable for Distributed Data Stores and comes into effect when Network Partition (P) happens. It says when (P) happens then the Distributed Data Store has to chose between Consitency (C) or Avaiability (A).

    i.e. when P happens then either it will be PA or PC.

    RDBMS used to be PC but with time they have started supporting PA as well.

    Coming to Redis specifically, High Availability is more than being Partition Tolerance. Redis has Master Slave architecture and if a Master fails then Redis Sentinels promote a Slave to be the new Master, making the entire solution highly available. And a master can fail (or become unavailable) for number of reasons (e.g. out of memory), it isn't necessarily due to a Network Partition.

    Then comes the case of Network Partition (P), and if (P) happens then Redis becomes unvailable in the minority partition. That's why from CAP perspective, Redis is CP because it becomes unavailable in minority partitions. Please note it will still be available in majority partition.

    You can read more about Redis High Availability here. Refer para titled "Consistency under partitions" for details around Partitioning.

    Redis is also called eventually consistent because when (P) happens, the minority parition is still available for a few seconds and any writes done during that period on the minority parition will eventually get discarded.