Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is correct understandanding of Cassandra tunable consistency?

Tags:

cassandra

It is said consistency level N defines number of replicas needed to acknowledge every read and write operation.The bigger that number, the more consistent result we have.

If we define that parameter as N (N < M/2), where M is cluster size, does it mean the following situation is possible :

1 data center. two concurrent writes happened successfully(they updated the same key with different values)? And consequently, two subsequent concurrent reads return different values for the same key? Am i correct?

like image 798
voipp Avatar asked Dec 08 '25 10:12

voipp


2 Answers

Yes, we can tune consistency based on requirements for read and writes. Quorum is recommended consistency level for Cassandra for single DC. we can calculate from below Quorum =N/2+1 where N is number of replica. Consistency we can set from below command CONSISTENCY [level]

For more details on tunable consistency please refer below.

https://medium.com/dugglabs/data-consistency-in-apache-cassandra-part-1-7aee6b472fb4 https://docs.datastax.com/en/cassandra/3.0/cassandra/dml/dmlAboutDataConsistency.html

https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshConsistency.html

like image 74
LetsNoSQL Avatar answered Dec 11 '25 07:12

LetsNoSQL


In Cassandra it is highly possible that different client applications are updating value of same key on different nodes. You can restrict this always by tuning your consistency level.

Consistency Level always depends on Replication Factor decided by you.

If RF=3 from 5 nodes DC, then Consistency level QUORUM or LOCAL_QUORUM means 2 nodes out of 3 which are having replica.

Any of the below combination should give you correct data, after tuning:

WRITE=ALL READ=ONE  
WRITE=ONE READ=ALL  
WRITE=LOCAL_QUORUM READ=LOCAL_QUORUM  

You can tune consistency level in your application, as per load of the application.

According to me, Number 3 LOCAL_QUORUM should work better, As sometimes a node can be under high load or maybe is down. Your application will not get affected.

In case, you have more writes than READ; WRITE CL=ALL will make your application slow.

like image 20
Anil Kapoor Avatar answered Dec 11 '25 05:12

Anil Kapoor