Consistency levels in Cassandra

In this article, we are going to discuss consistency levels in Cassandra which is very helpful for high availability and high mechanism in Cassandra. let’s discuss one by one.

First here, we are going to define the scenario of keyspace in which we will show how we have a different data center and each data center contains 3 replicas. let’s have a look.

CREATE KEYSPACE cluster_consistency
with replication =  {'class' : 'NetworkTopologyStrategy', 
                     'DC1': 3, 'DC2': 3, 'DC3': 3}
AND DURABLE_WRITES = false; 

In the above CQL query, we have three different data centers such as DC1, DC2, and DC3. Each data centers have 3 replicas which simply means the replication factor is three (RF =3).

Let’ s consider a scenario such that there is three number of replication factors in each 3 data centers.

  • LOCAL_ONE :
    In this consistency level we needs 1 node to responds from the local dc to succeed.

  • LOCAL_QUORUM :
    In this consistency level, we Need 2 nodes to response from the local dc to succeed.

  • EACH_QUORUM :
    In this consistency level we Needs 2 nodes in each dc to succeed. so, from each data center if 2 node will responds then in this case 6 total nodes.

  • LOCAL_SERIAL :
    This consistency level is Like LOCAL_QUORUM. In this consistency level, we Need 2 nodes from the LOCAL DC to succeed. But, In LOCAL _SERIAL consistency level has a lot of extra traffic (at least 4x round trips) to enforce order and consistency in Cassandra.

  • ONE:
    In this consistency level, write consistency level for ONE is must be written to the commit log and memtable of at least one replica node. In this, we Need 1 node from the ANY DC to succeed.

  • TWO:
    In this consistency level, write consistency level for TWO is must be written to the commit log and memtable of at least two replica nodes. In this, we Need 2 nodes to the response from the ANY DC to succeed.

  • THREE :
    In this consistency level, write consistency level for THREE is must be written to the commit log and memtable of at least three replica nodes. In this, we Need 3 nodes to the response from the ANY DC to succeed.

  • QUORUM:
    In this consistency level, write consistency level is must be written to the commit log and memtable on a quorum of replica nodes across all datacenters. In this consistency level (n/2 +1) nodes Needs (9/2 +1) 5 nodes to the response from ANY DC to succeed.

  • SERIAL :
    It is Like QUORUM consistency. In this consistency, we Need 5 nodes from the ANY Data Center to succeed. But, In Serial level consistency also has a lot of extra traffic (at least 4x round trips) to enforce order and consistency.

  • ALL:
    In this consistency level, we Need all 9 replicas to succeed. so, In case of write consistency, If any node is down the write fails. In the case of read consistency level for ALL, that means all replicas have responded. It will fail if a replica does not respond.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.