...

/

Illustration: Apache Cassandra Consistency Levels

Illustration: Apache Cassandra Consistency Levels

Contrast the various consistency levels in Apache Cassandra through hands-on demonstrations using INSERT and SELECT statements across two different cluster configurations.

We'll cover the following...

For easy reference, the main Apache Cassandra consistency levels are listed in the table below, ordered by strongest to weakest consistency.

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

In this lesson, we will demonstrate each consistency level with a read and write query. To display how consistency level and the cluster node count affect query success, the INSERT and SELECT statements are executed on two configurations: a three-node Cassandra cluster and a one-node Cassandra cluster. Records are written to and read from courses_by_category table, Cassandra partition in the VideoCourses keyspace with a RF of 2.

The INSERT and SELECT statements executed for each consistency demonstration are listed below. Please note that the value of the title column in the INSERT statement will be set ...