Search code examples
cassandranosqlconsistencydata-consistency

Data consistency across nodes in NOSQL


This is a design level question,

I have a node setup like Node N1, N2 and N3 where my application and database (as of now consider as Cassandra) runs in all 3 nodes.

I need to provide the data consistency for the following scenario, Could someone provide answers?

  • Thread (T1) tries to edit the data in Node N1
  • Thread (T2) tries to edit the same data from Node N2
  • Only one write should succeed

In this case, what will happen in Cassandra?

Is there a way to provide the concurrency via application / Cassandra database? Or any Algorithms?

Apart from LWT in Cassandra.


Solution

  • Cassandra offers tunable consistency. In your case this only means, that if you offer CL=QUORUM for writes it will get synced to 2 out-of 3 nodes. Read will be consistent with CL=QUORUM as you will get results from 2 out-of 3 nodes, so there's an overlap.

    For writes Cassandra offers last-write-wins mechanism. This means that independently from consistency level a reader will either see T1 or T2 thread's write, depending on when the read happens. Later on reader will only see the latest write.

    If you want locking mechanism, you can use offline concurrency patterns in your application layer, like optimistic or pessimistic offline lock. Some of the persistency management frameworks offer these pattern implementation out-of-the-box.