Skip to content
SeeItFlow
Interactive guide · 9 chapters · ~24 min read

Cassandra Fundamentals

How Apache Cassandra distributes data across a cluster with no single master, replicates it for high availability, and lets you tune the trade-off between consistency and availability per query.

Mangesh MandlikLast updated:
01 · Foundations

Cassandra Architecture: What is Cassandra?

Apache Cassandra is a distributed, wide-column NoSQL database built to run across many commodity servers with no single point of failure and linear horizontal scalability.

Unlike a traditional relational database with a primary/replica topology, every node in a Cassandra cluster is functionally identical — there is no master node coordinating traffic. Any node can accept a read or write for any piece of data, hash it to find out which node(s) actually own it, and route the request accordingly.

Swipe to pan
N10x00N20x2AN30x55N40x80N50xAAN60xD5
A Cassandra cluster is a ring of peer nodes, each owning a range of tokens.

The defining characteristics

Wide-column

Data is organized into tables with rows and columns like a relational database, but each row can have a different set of columns — closer to a distributed, sorted map of maps than a fixed relational schema.

Masterless (peer-to-peer)

Every node runs the same code and can serve any request — there's no primary/replica split to manage or fail over.

Tunable consistency

Every read and write specifies a consistency level (ONE, QUORUM, ALL, ...) — the trade-off between latency and consistency is a per-query decision, not a global one.

Linear scalability

Adding nodes adds both storage and throughput roughly proportionally, because responsibility for the keyspace is spread evenly across all nodes.

Interactive

Visual Learning

Watch one masterless Cassandra cluster handle partitioning, replication, tunable consistency, gossip, failures, and compaction as a single continuous system — not sixteen separate explanations.

02 · History

Why Cassandra Was Created

Cassandra was built at Facebook to solve a problem relational databases couldn't: storing and searching a message inbox at a scale where a single master node — or even a sharded fleet of masters — became an operational nightmare.

Facebook engineers combined ideas from two influential systems: Amazon's Dynamo paper (for its masterless, highly available, partition-tolerant architecture using consistent hashing and gossip) and Google's Bigtable paper (for its wide-column, sparse, sorted data model). The result — Cassandra — was open-sourced in 2008 and became an Apache project in 2010.

03 · Data model

Partitions & Partition Keys

Every row in Cassandra belongs to a partition, and every partition is identified by a partition key — the single most important design decision in a Cassandra data model.

Partition key

The part of the primary key that determines which node(s) own a row. Cassandra hashes the partition key to compute a token, and the token determines placement on the ring.

Clustering columns

Additional key columns that determine the sort order of rows within a single partition — they don't affect placement, only ordering on disk.

04 · Distribution

Consistent Hashing & the Token Ring

Cassandra arranges every node on a logical ring by token — a position in the hash space — and consistent hashing is what decides which node owns which data.

Swipe to pan
N30x55N40x80hash(key)=0x60Walk clockwise → first node ≥ hash owns the key (Node 4)
A partition key hashes to a token; the first node clockwise from that token owns the data.

Every node is assigned one or more tokens (a range of the hash space it is responsible for). To place or find a row, Cassandra hashes its partition key into that same space and walks clockwise around the ring until it finds the first node whose token is greater than or equal to the hash — that node owns the data (and, with replication, the next N-1 nodes clockwise hold copies).

05 · Availability

Replication & Replication Factor

Every piece of data is stored on multiple nodes — the Replication Factor (RF) — so that the loss of any single node never means data loss.

Swipe to pan
CoordinatorNode 3replicaNode 4replicaNode 5replica
A write to a coordinator fans out to RF replicas in parallel.

Replication Factor (RF)

A per-keyspace setting: RF=3 means every row is stored on 3 different nodes. Common production values are RF=3 (single datacenter) or RF=3-per-datacenter for multi-DC deployments.

Coordinator node

Whichever node receives the client's request. It doesn't need to own the data itself — it just needs to know (via the ring topology) which nodes do, and forwards the request to them.

06 · Consistency

Consistency Levels

Cassandra doesn't force one consistency guarantee on every query — each read or write specifies how many replicas must respond before it's considered successful.

Swipe to pan
ONEReplica 1Replica 2Replica 31 of 3 must ackQUORUMReplica 1Replica 2Replica 32 of 3 must ackALLReplica 1Replica 2Replica 33 of 3 must ack
ONE, QUORUM and ALL trade off latency against durability and read-your-writes guarantees.

ONE

Only a single replica needs to acknowledge. Fastest and most available, but offers the weakest durability — if that one replica is lost before it syncs to others, the write is gone.

QUORUM

A majority of replicas (⌊RF/2⌋ + 1) must acknowledge. A common production choice (not a server-wide default; cqlsh starts at ONE and driver defaults vary) — combined with the R + W > RF overlap condition (covered below), it gives a strong read-your-writes guarantee for the common case. It is not automatically the same as linearizable consistency: clock skew, hinted handoff, and concurrent writes can still produce surprising orderings unless the workload needs the stronger, slower guarantees of lightweight transactions (LWT / SERIAL).

ALL

Every single replica must acknowledge. The strongest consistency, but the weakest availability — a single down replica blocks every request, which defeats much of Cassandra's purpose.

07 · Cluster coordination

Gossip Protocol & Hinted Handoff

With no master to track cluster state, Cassandra nodes gossip with each other to spread membership and health information, and use hinted handoff to keep writes flowing through short outages.

Swipe to pan
N1N2N3N4N5N6
Every node periodically exchanges state with a few random peers — information spreads exponentially.

Gossip protocol

Once per second, every node exchanges state (heartbeats, load, schema version, which nodes are up/down) with 1-3 random peers. Within a few rounds this information has propagated to the entire cluster — no broadcast, no central registry required.

Hinted Handoff

If a replica is temporarily unreachable during a write, the coordinator stores a 'hint' — the missed write — and replays it once the replica comes back, avoiding the need to block the write or run a full repair for short outages.

08 · Storage engine

The Write Path, SSTables & Compaction

Everything above decides *which replicas* handle a write. This chapter is what each replica does with it — an LSM-tree storage engine that never updates data in place.

Write path on a single replica

1. Commit log + memtable

The replica appends the mutation to the commit log (a sequential, append-only file used only for crash recovery) and applies it to the table's in-memory, sorted memtable. Only then does it acknowledge the coordinator. No read-before-write and no random disk I/O is involved, which is why writes are cheap. With the default periodic commit-log sync (commitlog_sync_period, 10 s by default), a replica may acknowledge a write before it has fsynced its commit log, so a sudden crash can lose that replica's unsynced tail. Replication and the chosen consistency level determine whether another replica still holds the write; they reduce the risk rather than guarantee survival (batch mode fsyncs before acknowledging, at a latency cost).

2. Flush to an SSTable

When memtable memory crosses its threshold, or the commit log reaches its size cap and has to free segments, the memtable is flushed to disk as an SSTable — an immutable, sorted file with its own partition index and Bloom filter. Commit-log segments are discarded once every memtable they cover has been flushed. After a crash, the surviving log is replayed into a fresh memtable.

3. Reads merge several sources

Because SSTables are never rewritten in place, one partition is usually spread over the memtable and several SSTables. A read consults the memtable plus each SSTable that might hold the partition (Bloom filters rule most out) and merges the results by timestamp — last write wins per cell. The more SSTables a read has to touch, the slower it gets.

Updates and deletes are writes

An update just writes a newer-timestamped cell; a delete writes a tombstone marker. Nothing is physically removed at write time, so old versions and tombstones sit in older SSTables until compaction rewrites them.

Compaction: keeping read cost bounded

Compaction merges several SSTables into new ones in the background: it keeps only the newest version of each cell, drops expired TTL data, and purges tombstones once they are eligible. It trades extra disk I/O and temporary disk space now for fewer SSTables per read later. The strategy is set per table and decides *which* files get merged together.

StrategyHow it groups SSTablesGood fitTrade-off
SizeTiered (STCS) — the defaultMerges SSTables of similar size once enough (by default 4) accumulateWrite-heavy workloads, general purposeLow write amplification, but a partition can span many SSTables (higher read amplification) and a big compaction can need a large share of free disk
Leveled (LCS)Fixed-size SSTables in levels; within a level (above L0) partitions do not overlapRead-heavy workloads, frequent updates, latency-sensitive readsA partition is typically in only a few SSTables, but data is rewritten repeatedly as it moves down levels (high write amplification)
TimeWindow (TWCS)One time window per bucket; STCS inside the current window, closed windows are left aloneTime-series data written once with a TTLExpired windows can be dropped whole, but out-of-order writes, updates and manual deletes break the model and keep old windows alive

Tombstones and gc_grace_seconds

A tombstone must outlive the window in which some replica might still hold the deleted data, otherwise a replica that missed the delete could resurrect the row. gc_grace_seconds (default 864000 s = 10 days) is that window: compaction will not purge a tombstone before it elapses, and repair must complete on every replica within it. Tombstones are also scanned on reads — by default Cassandra logs a warning at 1,000 tombstones in a single query and aborts the query at 100,000 (tombstone_warn_threshold / tombstone_failure_threshold; defaults as of Cassandra 4.1/5.0).

09 · Healing & trade-offs

Repair & the CAP Theorem

By default, Cassandra leans toward Availability and Partition tolerance over strict Consistency — and relies on read repair and anti-entropy repair to reconcile any divergence afterward. But that lean is configurable, not absolute.

Read repair

During a normal read at CL=QUORUM or higher, the coordinator compares timestamps across the replicas it happened to query. If one is stale, the newer value is written back in the background. This is an opportunistic, read-path mechanism — it only touches the replicas involved in that particular read, and rarely-read data can stay stale indefinitely without it.

Anti-entropy repair

A background process (nodetool repair) that compares full replica datasets using Merkle trees and synchronizes any differences across all replicas, not just the ones a recent read happened to touch. This — run on a schedule, typically within gc_grace_seconds — is the mechanism that actually guarantees comprehensive reconciliation; read repair alone is a nice-to-have, not a substitute for it.

CAP theorem in practice

During a network partition, Cassandra's default configuration keeps accepting reads and writes on both sides (Availability) rather than refusing requests to guarantee Consistency — the classic AP lean, as opposed to a single-master relational database, which typically chooses CP. But this is a tendency, not a fixed law: Cassandra is more accurately described as partition-tolerant and highly available by default, with tunable consistency — pushing reads and writes to QUORUM/ALL, or using lightweight transactions (LWT), moves specific queries much closer to CP behavior.

Key takeaways
  1. 01Cassandra is a masterless, wide-column database — every node can coordinate any request, eliminating a single point of failure.
  2. 02Consistent hashing places data on a token ring so that adding/removing nodes only reshuffles a small, bounded slice of the keyspace.
  3. 03Replication Factor (RF) determines how many copies of each row exist; Consistency Level (CL) determines how many must respond per query.
  4. 04QUORUM reads + QUORUM writes satisfy the R + W > RF overlap condition, giving a strong read-your-writes guarantee without paying for every replica to respond — for full linearizable consistency, reach for lightweight transactions (LWT).
  5. 05Writes go to the commit log and an in-memory memtable, then flush to immutable SSTables; compaction merges them in the background, so the strategy (STCS, LCS, TWCS) is a read-vs-write-amplification decision per table.
  6. 06Gossip spreads cluster membership without a coordinator; hinted handoff keeps writes flowing through short outages.
  7. 07Read repair is an opportunistic, read-path check; anti-entropy repair (nodetool repair) is the scheduled, comprehensive mechanism that actually guarantees replicas converge — together they reconcile divergence from Cassandra's availability-first, tunable-consistency design.