I'm new to distributed databases and there are a couple of things I couldn't figure out.
We're developing an application and need to select the right database,
this application needs strong consistency on financial data related to users, like deposit and withdraws.
I am wondering about tunable consistency in Cassandra, specifically quorum level of consistency.
Imagine the following scenario:
Replication factor is 3.
Initial balance of a user John is 10 on all replicas.
At time t1, an update is happening on John's balance reducing it to 7 (CL=quorum),
Simultaneously, at time t1, a read operation is being run with consistency level set on quorum which is 2 in this case.
Is it possible that the replica on the node where update query is executing on, is not selected for the quorum?
If so, Is it right to assume that the result of read
operation would be 10 because there's no write lock?
Overall I'd like to know if it is possible for John to somehow exploit this and spend more than his account's balance.
Thanks.
-
1What is the consistency level for update operation?– Alex OttNov 27, 2017 at 19:53
-
@AlexOtt Thanks for reminding me! I've edited the question, CL for the update operation is set on quorum.– SamNov 27, 2017 at 20:06
1 Answer
With having QUORUM for both read & write requrests you achieve strong consistency per following equation R + W > N
, where R
- read replica count, W
- write replica count, and N
- replication factor.
If you write with QUORUM, then 2 nodes will get fresh data, and when you read with QUORUM, then one node may have the old data, and one will have fresh data - Cassandra will detect discrepancy & use the newest version.
-
So basically my concern for 'double spending' problem due to old data is irrelevant. Am I getting this right?– SamNov 28, 2017 at 11:09
-
Yes - you are right. Although for money I maybe prefer to use consistency level ALL for writes...– Alex OttNov 28, 2017 at 12:20
-
Does this apply for MySQL master slave replication as well? Is there any tool to implement strong consistency across master and slaves using quorum for MySQL?– piepiDec 29, 2020 at 19:07
-