Tuesday 24 July 2018

Data Consistency in Cassandra

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.
LevelDescription
ALLReturns the data after all replicas have responded. The read operation will fail if any replica does not respond. It gives the highest consistency.
ONEReturns a response from the closest replica. The replicas contacted for reads may not always have the most recent write.
TWOReturns the most recent data from two of the closest replicas.
THREEReturns the most recent data from three of the closest replicas.
QUORUMReturns 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.
LevelDescription
ALLA 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.
ONEA data should be written to the commit log and memtable of at least one replica node.
TWOA data should be written to the commit log and memtable of at least two replica node.
THREEA data should be written to the commit log and memtable of at least three replica node.
QUORUMA data should be written to the commit log and memtable on a quorum of replica nodes.
EACH_QUORUMA data should be written to the commit log and memtable on a quorum of replica nodes in all data center.
LOCAL_QUORUMA data should be written to the commit log and memtable on a quorum of replica nodes in the same data center.
LOCAL_ONEA write must happen and successfully acknowledged by, at least one replica node in the local data center.
ANYA 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.

0 comments:

Post a Comment