DS201 Study Notes: Cassandra Consistency Levels

DS201 course study notes on Cassandra Consistency Levels: types of consistency levels and the availability-consistency tradeoff.

Study notes from DS201: Foundations of Apache Cassandra™ and DataStax Enterprise.

Consistency Level

Cassandra distributes and stores data across multiple nodes according to the Replication Factor (RF). The Consistency Level controls how many replica nodes must successfully acknowledge a read or write operation before the operation is considered complete and the client is notified.

The Consistency Level is used to adjust the tradeoff between availability and consistency. Setting a high consistency level guarantees data consistency but may reduce availability and performance. Conversely, setting a low consistency level improves availability and performance but may temporarily compromise data consistency.

Main Consistency Levels

Consistency LevelDescription
ANYRead or write operations are considered complete when they succeed on at least one replica (including the coordinator node itself). The lowest consistency level, maximizing availability.
ONERead or write operations are considered complete when they succeed on at least one replica. Unlike ANY, it waits for a response from other replica nodes, not the coordinator node itself.
TWORead or write operations are considered complete when they succeed on at least two replicas.
THREERead or write operations are considered complete when they succeed on at least three replicas.
QUORUMRead or write operations are considered complete when they succeed on a majority of replicas (RF / 2 + 1). For example, with RF=3, responses from 2 replicas are required.
ALLRead or write operations are considered complete when they succeed on all replicas. The highest consistency level, minimizing availability.
LOCAL_ONERead or write operations are considered complete when they succeed on any one replica in the local data center. Reduces latency by avoiding cross-data center communication.
LOCAL_QUORUMRead or write operations are considered complete when they succeed on a majority of replicas in the local data center. Useful in multi-data center environments for guaranteeing consistency within the local data center while avoiding cross-data center latency.
EACH_QUORUMRead or write operations are considered complete when they succeed on a majority of replicas in each data center. Useful in multi-data center environments for guaranteeing consistency within each data center.

Read and Write Consistency

In Cassandra, the Consistency Level for reads and writes can be set independently. For example, to guarantee “strong consistency,” the relationship between RF and Consistency Level is important.

  • Strong consistency: When the setting satisfies Read Consistency Level + Write Consistency Level > RF, strong consistency is guaranteed, always reading the latest data. For example, with RF=3, writing with QUORUM (2) and reading with QUORUM (2) gives 2 + 2 = 4 > 3, guaranteeing strong consistency.

Selecting the appropriate Consistency Level based on application requirements is critical for using Cassandra effectively.