Data Consistency in Cassandra
In Cassandra consistency is about how up-to-date and synchronized all replicas of a row of Cassandra data are at any given moment. Cassandra follows CAP theorem for providing high availability and partition tolerance.
The consistency level determines the number of replicas that need to acknowledge the success of any read/write operation to the client.
Read Consistency Levels
The read consistency level says how many replicas must respond to a read request before returning data to the client. Cassandra initiates a read repair to update the inconsistent data if a inconsistency among replicas is found during a read operation.
|ALL||Returns the data after all replicas have responded. The read operation will fail if any replica does not respond. It gives the highest consistency.|
|ONE||Returns a response from the closest replica. The replicas contacted for reads may not always have the most recent write.|
|TWO||Returns the most recent data from two of the closest replicas.|
|THREE||Returns the most recent data from three of the closest replicas.|
|QUORUM||Returns the data after a quorum of replicas has responded from any data center.|
Write Consistency Levels
The write consistency level specified how many replicas must respond to a write request before the write is considered successful.
|ALL||A data should be written to the commit log and memtable on all replica nodes in the cluster for the given partition key. It provides the highest data consistency.|
|ONE||A data should be written to the commit log and memtable of at least one replica node.|
|TWO||A data should be written to the commit log and memtable of at least two replica node.|
|THREE||A data should be written to the commit log and memtable of at least three replica node.|
|QUORUM||A data should be written to the commit log and memtable on a quorum of replica nodes.|
|EACH_QUORUM||A data should be written to the commit log and memtable on a quorum of replica nodes in all data center.|
|LOCAL_QUORUM||A data should be written to the commit log and memtable on a quorum of replica nodes in the same data center.|
|LOCAL_ONE||A write must happen and successfully acknowledged by, at least one replica node in the local data center.|
|ANY||A write must be written to at least one node. It gives a low latency and a guarantee that a write never fails.|
Consistency for individual read or write operations can vary to make the data returned is more or less consistent, as required by the user. Higher consistency incurs higher latency, lower consistency permits lower latency. Latency can be controlled by tuning consistency.