Cassandra – Handling Read Conflicts

cassandraconsistency

Say we have three nodes(simple replica no sharding) i.e. N1,N2 and N3 with replication factor as 3.

  1. As read and write request can go to any node, Say Request write request(to update the same record at same time) comes and goes
    node N1.

  2. Read request comes to read the same document and goes to node N2. I believe it will return stale data as write is not replicated to N2 yet ?
    Consider the default configuration where i have not tuned the read and write concerns.

  3. I believe problem in step2 can be resolved with either of below options

    a. In synch replication, Good for strong consistency but bad for performance

    b. Tuning read and write consistency as explained at read and write consistency

    c. With the help of sharding(if required), where shard key will ensure all read and writes goes to particular node for particular shard key ?

Is my understanding in point 2 and 3 correct?

Best Answer

Mostly yes, but with small correction. You can get the stale data if they aren't replicated yet to another node (replication happens almost at the same time, but still could be delayed because of garbage collection, etc.). You can get strong consistency by tuning consistency levels...

The comment is about point 3c - Cassandra's partitions are replicated to all nodes that were selected as replicas for particular partition - the driver or coordinator node can come to any of them, depending on multiple factors. There is no such thing as an additional sharding key that will route to specific node - all replica nodes are equal.