Consistency Levels: THREE, TWO, ONE, LOCAL_ONE, and ANY
Learn the various Consistency levels featured in Apache Cassandra, and how they impact data consistency, availability, and performance.
We'll cover the following...
The table below lists the main Apache Cassandra consistency levels, arranged from strongest to weakest.
CL | Replica(s) contacted for read/write | Availability vs. Data Accuracy |
| Every replica in the cluster |
|
| Majority (51%) replicas in each datacenter. Heavy operation. Rarely used |
|
| Majority (51%) of replicas across all datacenters ((RF1+RF2+..RFn) /2) +1 |
|
| Closest 51% replicas in the same datacenter (RF/2)+1 |
|
| 3 replicas closest to coordinator |
|
| 2 replicas closest to coordinator |
|
| 1 replica closest to coordinator |
|
| Closest replica to coordinator in the same datacenter |
|
| For write operations only. No acknowledgement required. Hint is stored by coordinator & write succeeds even if all replicas are down |
|
Numeric consistency levels: THREE
/ TWO
/ ONE
A Cassandra cluster allows horizontal scaling with the addition of nodes to the cluster. For consistency levels ALL
, QUORUM
, LOCAL_QUORUM
, EACH_QUORUM
, etc., the read/write operation latency increases with the increase in the number of nodes/replicas. A numeric consistency level allows selecting a fixed number of replicas to acknowledge a read/write operation, irrespective of the replica count. By using numeric consistency levels independent of the replication factor, network latency can be minimized, leading to faster response times and higher availability at the expense of data consistency.
The THREE
consistency level
The THREE
consistency level requires responses from exactly three replicas for an operation (read or write) to be considered successful. The key features of the THREE
consistency level are listed below:
Write acknowledgment awaited from three replica nodes.
Fast write.
Data read from three replica nodes.
Fast read.
Offers a higher degree of consistency as compared to
ONE
andTWO
.Consistency level
THREE
provides increased fault tolerance and data accuracy, as compared to other numeric consistency levels, by ensuring that data is replicated on at least three nodes.
The following statement sets the consistency for all read and write queries in the current session to THREE
:
CONSISTENCY THREE;
The screenshots below illustrate execution of the INSERT
and SELECT
statements with THREE
...