...

/

Consistency Levels: THREE, TWO, ONE, LOCAL_ONE, and ANY

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.

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

ALL

Every replica in the cluster

  • Strongest consistency (maximum accuracy)
  • Minimum availability

EACH_QUORUM

Majority (51%) replicas in each datacenter. Heavy operation. Rarely used

  • In multi-datacenter deployments, EACH ensures same consistency across datacenters
  • 2nd strongest consistency
  • Weak availability

QUORUM

Majority (51%) of replicas across all datacenters

((RF1+RF2+..RFn) /2) +1

  • Strong consistency
  • Balance between availability & accuracy

LOCAL_QUORUM

Closest 51% replicas in the same datacenter (RF/2)+1

  • In multi-datacenter deployments, LOCAL avoids inter-datacenter communication
  • Increasing availability while sacrificing accuracy

THREE

3 replicas closest to coordinator

  • Weak consistency
  • Strong availability
  • Used when consistency requirements are not stringent

TWO

2 replicas closest to coordinator

  • Weak consistency
  • Strong availability
  • Minimum fault-tolerance

ONE

1 replica closest to coordinator

  • Weakest consistency
  • Maximum availability
  • Sacrifices accuracy for availability

LOCAL_ONE

Closest replica to coordinator in the same datacenter

  • In multi-datacenter deployments, when ONE is the desirable consistency and cross-datacenter communication is to be avoided
  • Weakest consistency
  • Maximum availability


ANY

For write operations only. No acknowledgement required. Hint is stored by coordinator & write succeeds even if all replicas are down

  • Maximum availability
  • Minimum accuracy

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 and TWO.

  • 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 ...