SENIORCHAPTER 25

Wide-column stores: Cassandra and Bigtable

Partition keys, clustering, quorum maths, tombstones and compaction: Bigtable's storage engine under Dynamo's replication, and where each half bites

60 MINDATABASESUPDATED 2026-11-02
PREDICT

A 3-node Cassandra cluster, replication factor 3. To clear space fast, an engineer sets gc_grace_seconds = 0 on a table, deletes 50,000 rows at QUORUM while node C is down for maintenance, then runs a major compaction on A and B. Node C comes back an hour later. What does a QUORUM read of those rows return?

A wide-column store is two papers stitched together. From Google’s Bigtable (2006) it takes the data model and the storage engine: a sorted map of rows, written to a memtable and flushed to immutable SSTables, merged by compaction. From Amazon’s Dynamo (2007) it takes the distribution: a hash ring with no leader, every node equal, replicas found by hashing the key, tunable quorums, hinted handoff, read repair and Merkle-tree anti-entropy. Cassandra is the most widely run result. You met the storage half in the chapter on LSM trees; this chapter is about the data model you are forced into, the distribution half, and the places where the two halves interact badly.

The lineage, and what the name means

“Wide-column” is a misleading name. It does not mean columnar storage; the chapter on columnar analytics is about a different thing entirely. It means that one row key can hold a very large, sparse, sorted set of columns, so a single “row” in Bigtable’s sense can carry thousands or millions of values. In modern Cassandra that idea is expressed as a partition holding many sorted rows.

system year data model from distribution consistency notes
Bigtable 2006 itself: row, column family, qualifier, timestamp range-partitioned tablets, one server per tablet, Chubby for locks, GFS underneath strong per row (single server owns each row) Google internal, sold as Cloud Bigtable since 2015
HBase 2008 Bigtable, closely range-partitioned regions, HDFS underneath, ZooKeeper strong per row the open-source Bigtable; one RegionServer per region
Cassandra 2008 (Facebook inbox search) Bigtable Dynamo: consistent hashing, leaderless replication, gossip tunable per request Avinash Lakshman co-wrote Dynamo; Apache top-level since 2010
ScyllaDB 2015 Cassandra (speaks CQL and its wire protocol) Cassandra’s, plus shard-per-core inside a node tunable C++ on Seastar; no JVM, no GC pauses

The split matters for what can go wrong. Bigtable and HBase have one owner per key range, so a row is strongly consistent and a failed server makes its ranges unavailable until another server takes them over. Cassandra and ScyllaDB have no owner: any replica accepts any write, so the store stays writable through failures and pays for it with the convergence machinery below.

Partition keys and clustering columns

In CQL a table’s primary key has two parts. Here is the shop’s orders, modelled for the one question the order history page asks, “this customer’s recent orders, newest first”:

CREATE TABLE shop.orders_by_customer (
    customer_id bigint,
    created_at  timestamp,
    order_id    bigint,
    status      text,
    total_cents int,
    PRIMARY KEY ((customer_id), created_at, order_id)
) WITH CLUSTERING ORDER BY (created_at DESC, order_id DESC);

The partition key, customer_id, is hashed with Murmur3 to a 64-bit token. The token decides which nodes hold the partition; that is the whole of the placement logic, and the consistent hashing lesson has the ring. The clustering columns, created_at and order_id, decide the order of rows inside the partition. On disk a partition is one contiguous, sorted run in each SSTable, with a row index every 64 KiB (16 KiB with 5.0’s BTI format; column_index_size) so a read can seek into the middle of it.

customer_id = 51murmur3 → one 64-bit tokenABCDtoken lands here; walk clockwise:replicas B, C, D (RF = 3)partition 51 on replica B (illustrative)2026-10-30 · order 1 998 712 · shipped2026-10-12 · order 1 990 004 · shipped2026-09-28 · order 1 981 377 · cancelled… sorted by created_at DESC, order_id DESC

What follows from this is the rule that shapes every Cassandra schema: a query must name the partition key with equality, and may only range over clustering columns in their declared order. WHERE customer_id = 51 AND created_at >= '2026-01-01' reads one contiguous slice from one partition. WHERE status = 'paid' would have to read every partition on every node, so Cassandra refuses it unless you add ALLOW FILTERING, which in production is a full cluster scan with a polite name.

So you model one table per query, and you write the same order to several tables. The shop’s relational schema from module 1 becomes, for the same three screens:

query table partition key clustering
a customer’s orders, newest first orders_by_customer customer_id created_at DESC, order_id DESC
one order with its lines order_lines order_id line_no
today’s orders waiting to ship ship_queue (status, day) order_id

There is no join and no foreign key. Keeping the three tables in step is your application’s job, usually with a logged BATCH (which guarantees all statements eventually apply, at the cost of an extra batchlog write to other nodes, but gives no isolation) or with change events. This is the denormalisation the modelling chapter warned about, done on purpose and at scale.

Partition size is the knob you set once

A partition lives on RF nodes and cannot be split. If it grows without bound, it becomes a hot spot that no amount of hardware fixes. The working limits:

  • Keep partitions under about 100 MB and 100,000 rows. Past that, compaction of the partition, repair streaming and reads that touch it get slow, and on the JVM a large partition read means large heap allocations and GC pauses. Cassandra 5.0 ships guardrails, partition_size_warn_threshold and partition_size_fail_threshold, off by default; turn the warning on.
  • A partition key with low cardinality concentrates load. Partitioning the ship queue by status alone puts every paid order in the world on three nodes.
  • A partition key that grows with time needs a bucket: (channel_id, bucket) where the bucket is a fixed time window. Discord partitions messages exactly this way, and still found a single busy channel-and-bucket pair could raise latency for the whole cluster, because every QUORUM read touching those replicas queued behind it.

In the shop, the 2% of heavy customers (ids 1, 51, 101, …) place 30% of the orders: about 60 orders each over three years at scale 1, a few kilobytes per partition. That is fine. A per-product table of every order line, order_lines_by_product, would put a best-selling SKU’s entire history in one partition; that table needs a month bucket in its key from day one, because changing a partition key later means rewriting the table.

Writes, timestamps and last-write-wins

A Cassandra write is an append: no read before the write, no check that the row exists. INSERT and UPDATE are both upserts. Every cell carries a write timestamp in microseconds, and when two versions of a cell meet, during a read or a compaction, the higher timestamp wins. That is the whole conflict-resolution model: last write wins, per cell. The vector clocks lesson shows what Dynamo did instead and what Cassandra gave up.

Three consequences catch teams:

  1. Clock skew loses writes. Timestamps come from the client driver or the coordinator’s clock. If one application server’s clock runs 2 seconds fast, its writes beat every honest write for the next 2 seconds, silently. NTP on every client host is part of your database’s correctness.
  2. There is no rollback. A write at QUORUM that times out may have reached one replica, or all three. The client gets WriteTimeout and does not know which. If it reached one, that version will spread through read repair or anti-entropy repair later, so a write the application saw fail can appear an hour afterwards. Writes must be idempotent so a retry is safe.
  3. Read-modify-write needs Paxos. UPDATE inventory SET on_hand = 4 WHERE product_id = 42 IF on_hand = 5 is a lightweight transaction: a Paxos round among the replicas, at SERIAL consistency. Classic Paxos takes four round trips where a plain write takes one, and contended LWTs on one partition time out under load. Cassandra 4.1 added a cheaper Paxos v2 (paxos_variant: v2). Do not mix LWT and non-LWT writes on the same cells: the plain write ignores the Paxos state and can overwrite a conditional update.

Replication and quorum maths

The keyspace sets the replication factor, per datacentre with NetworkTopologyStrategy:

CREATE KEYSPACE shop WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3};

Each request then picks a consistency level: how many of the RF replicas must acknowledge before the coordinator answers. With N replicas, W acknowledgements per write and R replies per read, if R + W > N, every read set overlaps every write set, so at least one replica in any read has the latest acknowledged write and its timestamp wins.

consistency level replicas needed at RF = 3 nodes you can lose R + W with the same level on both sides
ONE 1 2 2: no overlap, stale reads possible
QUORUM 2 (floor(RF/2) + 1) 1 4 > 3: overlap
ALL 3 0 6 > 3: overlap, no availability margin
LOCAL_QUORUM 2 in the local datacentre 1 per DC overlap within the DC, no cross-DC wait
ANY (writes only) 0: a stored hint counts all replicas not a durability promise at all

Mixed levels are legitimate: W = ALL, R = ONE gives overlap with cheap reads and makes every write fail when one node is down. Most production clusters run LOCAL_QUORUM both ways with RF 3 per datacentre, which survives one node per DC and keeps the cross-ocean round trip, 70 to 150 ms, off the request path. The price is that two datacentres can disagree for as long as replication between them lags.

Overlap is what the arithmetic promises. Here is what it does not:

  • It assumes every replica in the set holds the data. A node that joined without streaming (Monzo’s auto_bootstrap: false), a node restored from an old backup, or a node whose disk was wiped will answer with authority about data it never received. Nothing in the protocol distinguishes “I have no row” from “I lost the row”.
  • It is not linearizability. Two concurrent QUORUM reads during an in-flight QUORUM write can see new then old. Last-write-wins on timestamps decides concurrent writes, not arrival order. The consistency chapter in this module places this on the Jepsen map.
  • Hints do not count. Unlike Dynamo’s sloppy quorum, Cassandra counts only real replicas towards QUORUM, so a write with two of three replicas down fails with Unavailable rather than being parked elsewhere. Only ANY counts a hint.

How replicas converge

A replica that misses a write has three ways to catch up, each with a limit.

Hinted handoff. When a replica is down, the coordinator stores a hint, the missed mutation addressed to that node, on its own disk and replays it when gossip reports the node up again (the gossip lesson covers how nodes learn that). Hints are written only for the first max_hint_window, 3 hours by default. A node down for 4 hours misses everything after hour 3, permanently, until a repair. Hints are best-effort: the coordinator can die with them.

Read repair. When a read at a level above ONE contacts several replicas, the coordinator asks one for data and the others for a digest (a hash). On a mismatch it fetches full data from all of them, merges by timestamp, returns the newest, and with the default table option read_repair = 'BLOCKING' writes the merged result back to the stale replicas it contacted before answering. Two limits: only replicas involved in the read are repaired, and reads at ONE never repair anything. Cassandra 4.0 removed read_repair_chance and the background read repair that went with it, so a partition nobody reads at QUORUM is never repaired by reads.

Anti-entropy repair. nodetool repair builds a Merkle tree of each token range on each replica, compares the trees and streams the ranges that differ. It is the only mechanism that guarantees convergence, and it is expensive: it reads every partition in the range. Incremental repair (what nodetool repair runs by default, and reliable since the 4.0 rework) marks repaired SSTables so the next run only compares new data; full repair (nodetool repair -full) compares everything. Tools such as Cassandra Reaper schedule it in small sub-range slices so it never saturates a node.

These three tie back to tombstones through one setting.

Tombstones in a distributed store

The LSM chapter showed why a delete is a write: a tombstone that shadows older versions until compaction merges them. Distribution adds a requirement. A tombstone must outlive every replica’s chance to learn about the delete, or a replica that missed it will resurrect the data, which is the Predict above. That is gc_grace_seconds, 864,000 seconds (10 days) by default, per table. The contract it imposes on you: every replica of every table must complete a repair at least once every gc_grace_seconds. If repair has been failing quietly for two weeks, the next compaction can bring deleted rows back.

What creates tombstones is wider than DELETE:

you write tombstone created
DELETE FROM t WHERE pk = ? AND ck = ? one row tombstone
DELETE FROM t WHERE pk = ? AND ck < ? one range tombstone (two markers), however many rows it covers
INSERT with a null value for a column a cell tombstone per null column; use unset values in prepared statements
UPDATE t SET tags = {...} on a non-frozen collection a range tombstone over the old collection, every time
any data written USING TTL becomes a tombstone when it expires, on every replica independently

Reads count the tombstones they step over. At tombstone_warn_threshold, 1,000 per query, Cassandra logs a warning and sends it to the client; at tombstone_failure_threshold, 100,000, it aborts the read with TombstoneOverwhelmingException, which the client sees as a ReadFailure. The thresholds exist because a replica holds every tombstone it scanned in heap to send to the coordinator.

The pattern that hits both thresholds is the queue: a partition where rows are inserted and deleted as work moves through, such as the shop’s ship_queue keyed by (status, day). Every shipped order leaves a tombstone in the paid partition, and “give me the next 10 paid orders” scans past all of them from the head of the partition. The fixes are structural: time-bucket so old partitions are never read, delete with a single range delete up to a high-water mark instead of one tombstone per row, or keep the queue somewhere designed for it.

There is one case where lowering gc_grace_seconds is safe: a table written only with TTLs and never deleted or updated. Every replica expires the data on its own clock, so there is no delete for a replica to miss. Replicas skip tombstones older than gc_grace_seconds before counting them, so on such a table, lowering it also stops expired data from tripping the thresholds.

Compaction strategies in Cassandra

The LSM chapter covered levelled and tiered compaction in RocksDB. Cassandra names them differently, and adds one for time series:

strategy how it works fits fails when
SizeTieredCompactionStrategy (STCS), the default in cassandra.yaml merge 4 to 32 SSTables of similar size write-heavy, rarely read a major compaction needs free space equal to the table; a partition spread over many SSTables makes reads probe many files; tombstones in big old files wait a long time for a merge
LeveledCompactionStrategy (LCS) 160 MB SSTables in levels with fanout 10; one sorted run per level read-heavy, updates and deletes, tight read latency sustained high write rates: write amplification over 10 and compaction falls behind
TimeWindowCompactionStrategy (TWCS) STCS inside each time window (for example 1 day); windows never merge once closed append-only time series with a TTL out-of-order writes, deletes or updates to old rows mix windows, so whole files never expire
UnifiedCompactionStrategy (UCS), new in 5.0 one strategy with a per-level scaling_parameters: T4 behaves like STCS, L10 like LCS; SSTables sharded by token range so compactions run in parallel most new tables; the default in cassandra_latest.yaml it is new: test before migrating a large production table

TWCS is the one to understand fully because it makes TTL deletes almost free. With 1-day windows and a 90-day TTL, the table holds about 90 closed windows; when every row in the oldest window’s SSTable has expired and gc_grace_seconds has passed, Cassandra deletes the whole file without reading it. That is the same trick as FIFO compaction in RocksDB, made safe by windows. One update to a 60-day-old row puts a fresh cell in today’s window that overlaps an old one, and the old file can no longer be dropped until the new one expires too.

Watch nodetool compactionstats for pending tasks. A number that only grows means compaction cannot keep up: reads probe more SSTables, latency rises, and Discord’s team, running 177 Cassandra nodes in 2022, described falling behind on compaction as the start of cascading latency, alongside JVM garbage-collection pauses that needed operators to reboot nodes. Their move to 72 ScyllaDB nodes took p99 read latency from 40 to 125 ms down to 15 ms.

What goes wrong, and the signal for each

  • A node answers without the data. Bootstrap skipped, restore from an old snapshot, a wiped disk rejoining with the same identity. Signal: a jump in “not found” rates after a topology change. Fix: never join a node to serve reads before it streams; if you must, run nodetool repair on it before it takes traffic, and read at QUORUM while it does.
  • Repair stopped running. Nothing visible until gc_grace passes and a compaction resurrects data. Signal: the age of the last successful repair per table; alert at half of gc_grace_seconds.
  • A node was down longer than max_hint_window. Hints stopped after 3 hours. Fix: repair the node when it returns, before trusting ONE reads from it.
  • Tombstone warnings in the log. Find the table with nodetool tablestats (“Maximum tombstones per slice”) and fix the access pattern, not the threshold.
  • Large partitions. “Compacted partition maximum bytes” in tablestats, and the 5.0 guardrails. Fix the key; you cannot fix the partition.
  • Pending compactions climbing. Raise compaction_throughput (64 MiB/s by default) if the disks have headroom; otherwise reconsider the strategy or add nodes.
LAB Model the shop in Cassandra, drown a read in tombstones, then break a quorum ~60 MIN
YOU NEEDDocker with Compose v2the shop running and loaded (labs/databases, scale 1 or 0.1)Docker Desktop memory at 3 GB for steps 1 to 5 and at least 8 GB for steps 6 to 9 (three nodes at 2 GB each plus Postgres)about 2 GB of free disk

You will run Cassandra 5.0.9 next to the shop, load about 200,000 of its orders into a query-first table, produce a tombstone warning and a tombstone failure, then grow to three nodes and produce a stale read that QUORUM would have prevented. Each node runs with a 1 GB heap (MAX_HEAP_SIZE=1G, HEAP_NEWSIZE=200M; the image’s cassandra-env.sh needs both set together) and a 2 GB container limit, so the three-node part fits a 16 GB laptop.

1. Start one node. From labs/databases/, create the directory d3-cassandra/ and in it compose.yaml:

# labs/databases/d3-cassandra/compose.yaml
name: d3-cassandra
x-node: &node
  image: cassandra:5.0.9
  mem_limit: 2g
  environment:
    CASSANDRA_CLUSTER_NAME: atlas
    CASSANDRA_SEEDS: cass1
    CASSANDRA_ENDPOINT_SNITCH: GossipingPropertyFileSnitch
    CASSANDRA_DC: dc1
    MAX_HEAP_SIZE: 1G
    HEAP_NEWSIZE: 200M
  volumes:
    - ./:/lab
  healthcheck:
    test: ["CMD-SHELL", "cqlsh -e 'SELECT release_version FROM system.local' || exit 1"]
    interval: 10s
    timeout: 10s
    retries: 30
    start_period: 40s

services:
  cass1:
    <<: *node
    ports: ["9042:9042"]
  cass2:
    <<: *node
    profiles: ["ring"]
    depends_on: { cass1: { condition: service_healthy } }
  cass3:
    <<: *node
    profiles: ["ring"]
    depends_on: { cass2: { condition: service_healthy } }
cd d3-cassandra
docker compose up -d --wait cass1
docker compose exec cass1 nodetool status
After 40 to 90 seconds --wait returns and nodetool status shows Datacenter: dc1 and one line starting UN (Up, Normal) with 16 tokens. The depends_on chain in the file makes cass2 and cass3 join one at a time later, because Cassandra refuses to bootstrap two nodes into the same ranges at once.

2. Create the query-first table and load it from Postgres. Create d3-cassandra/schema.cql:

CREATE KEYSPACE IF NOT EXISTS shop
  WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 1};

CREATE TABLE IF NOT EXISTS shop.orders_by_customer (
    customer_id bigint,
    created_at  timestamp,
    order_id    bigint,
    status      text,
    total_cents int,
    PRIMARY KEY ((customer_id), created_at, order_id)
) WITH CLUSTERING ORDER BY (created_at DESC, order_id DESC);

CREATE TABLE IF NOT EXISTS shop.ship_queue (
    status      text,
    day         date,
    order_id    bigint,
    customer_id bigint,
    PRIMARY KEY ((status, day), order_id)
);

Export the orders of customers 1 to 50,000 (a tenth of the customers at scale 1, all of them at scale 0.1) in a timestamp format cqlsh COPY parses, and load them:

docker compose -f ../compose.yaml exec -T db psql -U atlas -d shop -c "COPY (SELECT customer_id, to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS.MS') || '+0000' AS created_at, id AS order_id, status, total_cents FROM orders WHERE customer_id <= 50000) TO STDOUT WITH (FORMAT csv, HEADER)" > orders.csv
wc -l orders.csv
docker compose exec cass1 cqlsh -f /lab/schema.cql
time docker compose exec cass1 cqlsh -e "COPY shop.orders_by_customer (customer_id, created_at, order_id, status, total_cents) FROM '/lab/orders.csv' WITH HEADER = true"
wc -l prints about 200,001 at either scale: at scale 1 those customers place a tenth of 2,000,000 orders, and at scale 0.1 they are every customer, with 200,000 orders. COPY reports its progress and ends with a line like 200000 rows imported from 1 files in 12.3 seconds (0 skipped). That is 10,000 to 30,000 rows a second through one coordinator and one memtable, with no index maintenance and no read before each write.

3. Ask the questions the table was built for, and one it was not.

docker compose exec cass1 cqlsh -e "SELECT created_at, order_id, status FROM shop.orders_by_customer WHERE customer_id = 51 LIMIT 5;"
docker compose exec cass1 cqlsh -e "SELECT count(*) FROM shop.orders_by_customer WHERE customer_id = 51 AND created_at >= '2026-01-01';"
docker compose exec cass1 cqlsh -e "SELECT count(*) FROM shop.orders_by_customer WHERE status = 'paid';"
docker compose exec cass1 nodetool flush shop
docker compose exec cass1 nodetool tablestats shop.orders_by_customer | grep -E 'SSTable count|Number of partitions|Compacted partition maximum bytes'
The first query returns customer 51’s five newest orders in descending date order, straight from the clustering order: no sort step exists to show. The second counts one slice of one partition. The third fails with InvalidRequest and the message Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING. tablestats shows about 47,000 partitions (one per customer with at least one order) and a maximum partition of a few kilobytes, the heavy customers. The status question needs its own table, and that is the modelling rule.

4. A queue that leaves tombstones behind. Put 5,010 paid orders in one day’s partition, then “ship” 5,000 of them by deleting them one at a time, the way a worker would:

seq 1 5010 | awk '{print "paid,2026-10-01," $1 "," $1 % 500}' > queue.csv
seq 1 5000 | awk -v q="'" '{print "DELETE FROM shop.ship_queue WHERE status = " q "paid" q " AND day = " q "2026-10-01" q " AND order_id = " $1 ";"}' > ship.cql
docker compose exec cass1 cqlsh -e "COPY shop.ship_queue (status, day, order_id, customer_id) FROM '/lab/queue.csv'"
docker compose exec cass1 cqlsh -f /lab/ship.cql
docker compose exec cass1 nodetool flush shop
docker compose exec cass1 cqlsh -e "TRACING ON; SELECT order_id FROM shop.ship_queue WHERE status = 'paid' AND day = '2026-10-01';"
Ten rows come back (orders 5001 to 5010), then a warning and a trace. The trace contains Read 10 live rows and 5000 tombstone cells, and because 5,000 is past tombstone_warn_threshold (1,000) the client also prints a warning naming the threshold. Ten useful rows cost five thousand units of work. Every real queue in Cassandra grows this way until someone notices the warning.

5. Cross the failure threshold with TTLs, then fix it. 120,000 rows that expire after one second:

seq 1 120000 | awk '{print "paid,2026-10-02," $1 "," $1 % 500}' > flood.csv
docker compose exec cass1 cqlsh -e "COPY shop.ship_queue (status, day, order_id, customer_id) FROM '/lab/flood.csv' WITH TTL = 1"
sleep 5
docker compose exec cass1 cqlsh -e "SELECT order_id FROM shop.ship_queue WHERE status = 'paid' AND day = '2026-10-02' LIMIT 10;"
docker compose exec cass1 cqlsh -e "ALTER TABLE shop.ship_queue WITH gc_grace_seconds = 0;"
docker compose exec cass1 cqlsh -e "SELECT order_id FROM shop.ship_queue WHERE status = 'paid' AND day = '2026-10-02' LIMIT 10;"
docker compose exec cass1 nodetool flush shop
docker compose exec cass1 nodetool compact shop ship_queue
docker compose exec cass1 nodetool tablestats shop.ship_queue | grep -E 'SSTable count|Space used \(live\)'
The first SELECT fails with ReadFailure: Error from server: code=1300 [Replica(s) failed to execute read] and a reason of READ_TOO_MANY_TOMBSTONES: the partition has no live rows, so LIMIT 10 scans all 120,000 expired cells looking for ten and crosses tombstone_failure_threshold (100,000). After the ALTER the same query returns zero rows at once, because the replica skips tombstones older than gc_grace_seconds before counting them. The compaction then drops them from disk: one SSTable, and the live space falls to a few kilobytes. This was safe because the table has one replica. On RF 3 with real deletes it is the Predict at the top of the chapter.

6. Grow to three nodes. Skip steps 6 to 9 if Docker has less than 8 GB. Set the profile for the rest of the lab so Compose sees cass2 and cass3, start them, and create a keyspace with three replicas:

export COMPOSE_PROFILES=ring
docker compose up -d --wait
docker compose exec cass1 nodetool status
docker compose exec cass1 cqlsh -e "CREATE KEYSPACE shop3 WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3}; CREATE TABLE shop3.inventory (product_id bigint PRIMARY KEY, on_hand int);"
docker compose exec cass1 cqlsh -e "CONSISTENCY ALL; INSERT INTO shop3.inventory (product_id, on_hand) VALUES (42, 10);"
docker compose exec cass1 nodetool getendpoints shop3 inventory 42
Two to four minutes: cass2 bootstraps, becomes healthy, then cass3 does. nodetool status lists three UN lines with different addresses. getendpoints prints all three addresses, because with RF 3 on three nodes every node holds every partition. The insert at ALL succeeded, so all three replicas hold on_hand = 10.

7. Quorum maths with one node down, and a write that misses it.

docker compose stop cass3
docker compose exec cass1 nodetool status
docker compose exec cass1 cqlsh -e "CONSISTENCY QUORUM; SELECT on_hand FROM shop3.inventory WHERE product_id = 42;"
docker compose exec cass1 cqlsh -e "CONSISTENCY ALL; SELECT on_hand FROM shop3.inventory WHERE product_id = 42;"
docker compose exec cass1 nodetool disablehandoff
docker compose exec cass2 nodetool disablehandoff
docker compose exec cass1 cqlsh -e "CONSISTENCY ONE; UPDATE shop3.inventory SET on_hand = 3 WHERE product_id = 42;"
nodetool status shows one DN line. The QUORUM read returns 10: two of three is enough. The ALL read fails with Unavailable ... Cannot achieve consistency level ALL and 'required_replicas': 3, 'alive_replicas': 2. The coordinator knew before sending anything. The update at ONE succeeds on cass1 and cass2. With hinted handoff disabled, nobody keeps a copy for cass3.

8. The stale read. Bring cass3 back, then take the other two away so cass3 is the only replica a read can reach:

docker compose start cass3
docker compose exec cass1 nodetool status            # repeat until all three are UN
docker compose stop cass1 cass2
docker compose exec cass3 cqlsh -e "CONSISTENCY ONE; SELECT on_hand FROM shop3.inventory WHERE product_id = 42;"
docker compose exec cass3 cqlsh -e "CONSISTENCY QUORUM; SELECT on_hand FROM shop3.inventory WHERE product_id = 42;"
The ONE read returns on_hand = 10: an acknowledged write (3) is invisible, and nothing in the response says so. This is W = 1 plus R = 1 on N = 3, so 1 + 1 is not greater than 3. The QUORUM read fails with Unavailable instead of answering wrongly. That is the trade the consistency level makes: an error instead of a stale value.

9. Repair by reading.

docker compose start cass1 cass2
docker compose exec cass3 nodetool status            # repeat until all three are UN
docker compose exec cass3 cqlsh -e "CONSISTENCY ALL; TRACING ON; SELECT on_hand FROM shop3.inventory WHERE product_id = 42;"
docker compose stop cass1 cass2
docker compose exec cass3 cqlsh -e "CONSISTENCY ONE; SELECT on_hand FROM shop3.inventory WHERE product_id = 42;"
docker compose start cass1 cass2
The ALL read returns 3, and its trace shows the coordinator sending a data request and digest requests, finding a digest mismatch, reading full data and sending a repair mutation to the stale replica before it answers. The final ONE read on cass3 alone now returns 3: the blocking read repair wrote the newer cell to cass3. A QUORUM read would have repaired cass3 only if cass3 happened to be one of the two replicas it chose; ALL makes the lab deterministic, and nodetool repair shop3 would have done the same for every partition.
Run steps 7 and 8 again without the two disablehandoff commands (restarting cass1 and cass2 in step 9 already turned handoff back on, because the setting is not persisted). While cass3 is down, docker compose exec cass1 nodetool listpendinghints shows a hint for it; start cass3, wait 30 seconds, and the stale read in step 8 returns 3, because cass1 replayed the hint. Now shrink the hint window with docker compose exec cass1 nodetool setmaxhintwindow 5000 (milliseconds), stop cass3, wait 20 seconds before the update, and repeat: no hint is written, listpendinghints stays empty, and the stale read is back. That is what a node down for more than three hours looks like with the default window, and why it needs a repair before it serves reads at ONE. Clean up with docker compose down -v (with COMPOSE_PROFILES=ring still set, so all three nodes go).
DECIDE

The shop's shipment-tracking table takes courier pings: partition key (shipment_id, day), clustering ts, 20,000 writes per second, every row written once with a 90-day TTL, never updated or deleted. Reads fetch today's pings for one shipment. It runs SizeTieredCompactionStrategy on 2 TB disks at 60% full; during large compactions disks briefly hit 90% and p99 reads double. What do you change?

READING
  1. PAPER
    Bigtable: A Distributed Storage System for Structured Data Chang et al., 2006

    The data model and storage engine Cassandra and HBase inherited. Read it to see what one owner per row range buys in consistency; skip the Chubby and master sections unless you run HBase. Read: OSDI 2006; sections 2 (data model), 5.3 to 5.4 (tablet serving and compactions) and 6 (refinements: locality groups, Bloom filters).

  2. PAPER
    Dynamo: Amazon's Highly Available Key-value Store DeCandia et al., 2007

    The distribution half of Cassandra. Note where Cassandra departs: no sloppy quorum and last-write-wins timestamps instead of vector clocks; the reconciliation sections show what that gave up. Read: SOSP 2007; sections 4.2 to 4.7 (partitioning, replication, sloppy quorum, hinted handoff, Merkle-tree anti-entropy).

  3. PAPER
    Cassandra: A Decentralized Structured Storage System Lakshman and Malik, 2009

    Six pages from the Facebook authors. Short and dated, but it states plainly which parts came from Bigtable and which from Dynamo, and why inbox search wanted both. Read: LADIS 2009; section 5 (system architecture) is the stitching of the two papers above.

  4. DOC
    Apache Cassandra documentation: Dynamo (replication, consistency levels)

    The current, authoritative description of the ring, replication strategies, consistency levels and the convergence mechanisms. Read the consistency and replica synchronisation sections; skip token allocation details.

  5. POST
    About Deletes and Tombstones in Cassandra Alain Rodriguez (The Last Pickle), 2016

    The best operator's account of tombstone types, gc_grace_seconds, zombie data and how compaction decides it may purge. Some option names predate 4.0, but the mechanics are unchanged.

  6. POST
    Why Monzo wasn't working on July 29th Monzo, 2019

    The full timeline of the incident in the Why: a quorum of empty replicas, how they diagnosed it, and the recovery by replaying events. Read it as a lesson in what quorum assumes.

  7. POST
    How Discord Stores Trillions of Messages Discord, 2023

    Hot partitions, compaction falling behind and GC pauses on 177 Cassandra nodes, and the move to ScyllaDB. A real account of partition-key design meeting a skewed workload; skip the Rust data-services sections.

  8. DOC
    Unified Compaction Strategy (UCS)

    How 5.0's UCS expresses STCS and LCS as one scaling parameter and shards SSTables by token range. Read the overview and the scaling parameters; the density maths is optional.

All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.
NEXT: Columnar and analytics: ClickHouse, DuckDB, Parquet, the lakehouse →