Read Path Internals

Part 4 made every write a cheap append — and in doing so scattered each partition's history across many immutable files. This part is where that bill is paid: what one replica does to answer a read, from the in-memory filters and caches that avoid touching files, to the merge that reconciles the files it can't avoid. The consequence worth internalizing is that read cost is governed by how many SSTables a partition is spread across — and that tombstones, the delete markers Part 4 wrote, are the most common way that number and the work per file quietly explode.

The Full Read Path

A client read for partition key P goes to a coordinator, which at QUORUM with RF 3 sends one full data read and one digest read to replicas. On the replica serving the data read: the row cache, step 3, is checked first if enabled, and a hit returns the whole partition from memory. Otherwise the memtable is always read. Then for each SSTable on disk: min and max metadata can rule the file out with zero I/O; the Bloom filter, step 1, can say definitely not here and skip it; the key cache, step 2, can supply the exact offset and skip the index search; only on a miss does step 4 binary-search the SSTable index and read data pages, the disk I/O everything above tries to avoid. Step 5 merges the memtable and surviving SSTables, highest timestamp per cell wins, and the result returns to the coordinator. A digest replica runs the same path but returns only a hash.
One read on one replica — every check before step 4 exists to avoid its disk I/O Step numbers follow this part’s sections, not execution order — the row cache (step 3) is consulted first.

Scope: One Replica, Not the Whole Read

Scope of this part: steps 1-5 are what happens inside one replica once it has been asked. The coordinator-level half of a read — how many replicas get contacted, why only one of them returns actual data, and what rescues a read when a replica goes quiet — is covered in Part 3's start-to-finish read flow. The short version, because it changes how you read the costs below:

  1. A QUORUM read at RF=3 contacts exactly 2 replicas, not all 3.
  2. Only one of those runs the full path below and returns rows. The other returns a hash of its result, and only on a mismatch does it get asked for real data.
  3. So the per-SSTable costs in this part are paid in full by one replica per read, and paid in "compute the same result, return a few bytes of hash" form by the other. (The digest is an MD5 hash — 16 bytes, or 32 hex characters.)

The digest replica saves the network, not the disk. It still runs every step below to compute the hash — so a fragmented, tombstone-heavy partition costs I/O on both replicas a QUORUM read touches.

  • Guarantees: Every candidate source — row cache, memtable, every SSTable that survives pruning — is consulted and merged, so the replica returns its newest version of each cell.
  • Does not guarantee: A bounded number of files per read. That number is set by flush history and compaction, not by the query — the read path can only prune it, never cap it.

Step 1 — Bloom Filter

A bloom filter is a probabilistic data structure that answers: "Is this key definitely NOT in this file, or is it possibly in this file?"

True negative — 100% reliable

If the bloom filter says no, the key is definitely not in that SSTable. Skip it entirely.

False positive — possible

The bloom filter says yes, but the key is not actually there. Cassandra does an unnecessary disk read, finds nothing, and moves on.

Why This Matters for Read Latency

Each SSTable has its own bloom filter stored in memory. When a read comes in, Cassandra checks the bloom filter for every SSTable before touching disk. Most SSTables are eliminated immediately with no I/O cost. Only the ones that pass the bloom filter check require a disk read.

Tuning the False Positive Rate

The false positive rate is tunable per table (bloom_filter_fp_chance). A lower false positive rate requires a larger bloom filter (more memory). The trade-off: less memory vs. fewer unnecessary disk reads. For read-heavy tables with many SSTables, lowering this value reduces latency at the cost of heap pressure.

Timestamp Metadata: The Other Skip Mechanism

Bloom filters aren't the only skip mechanism — timestamp metadata matters too. Each SSTable records the min/max timestamp (and min/max clustering values) of the data it contains in its metadata. A query with a time bound — "the last 50 messages in this channel" — can skip entire SSTables whose time range is older than what the query needs, without consulting the bloom filter or touching disk.

  • Guarantees: No false negatives: a file the filter rejects truly does not contain the partition, so skipping it never loses data.
  • Does not guarantee: That a "possibly" means the data is there — or that a partition present in many files gets pruned at all. Bloom filters prune by partition key only, never by time or clustering range.

Step 2 — Key Cache

The key cache stores the on-disk position (file offset) of recently read partition keys. If a key is in the key cache, Cassandra skips the SSTable index binary search and seeks directly to the right position in the file.

This is effective for hot partitions that are read repeatedly. It does not cache the actual data, just the pointer to it.

Cache entry(SSTable, partition key) → byte offset where that partition's block starts in Data.db
GranularityPer-SSTable. A hot partition that's fragmented across 8 SSTables can have 8 separate key cache entries, one per file, each pointing to a different fragment.
What it savesThe index binary search. It does not save the seek or the data read itself.

Worked Example: Discord's Messages Table

messages (
  channel_id  bigint,   -- partition key
  message_id  bigint,   -- clustering key (Snowflake ID, time-ordered)
  author_id   bigint,
  content     text,
  PRIMARY KEY (channel_id, message_id)
)

Every message in a channel lives in the same partition (channel_id), ordered by message_id. A busy channel like #general is written to constantly, so its partition ends up spread across many SSTables — every memtable flush creates a new one.

A user opens #general → read on channel_id = 123:

StepWhat happens
Bloom filterChecks all ~30 SSTables. Most (holding other channels' data) say "definitely not here" — skipped, zero I/O. ~8 SSTables say "possibly," because #general is active enough to appear in most recent flushes.
Key cacheFor each of those 8 SSTables, need to know where channel 123's data starts. If #general was read recently (likely — busy channel, many viewers), the offset is cached: channel 123 → byte 48,392 in SSTable #27. Seek straight there. A quiet DM channel nobody's opened in days would miss here and require a binary search.
Row cacheCaches the entire partition. For #general, that partition is huge and constantly written to — caching it is wasteful, and every new message invalidates it anyway. This table would have row cache disabled. Row cache only pays off for small, read-heavy, rarely-updated partitions.

Is a Partition's Data Contiguous on Disk?

Within one SSTable: yes

An SSTable is written once, in a single pass, from a memtable flush (or compaction). At that moment, all of a partition's current data is serialized together, sorted by clustering key, as one unbroken block in Data.db.

Across SSTables: no

Each new flush that touches channel_id = 123 creates a new SSTable with another contiguous fragment — a different slice of message_ids from whatever was in memory at that flush. The partition as a whole is scattered across up to N files, each holding one contiguous piece.

Three SSTables from three flushes, oldest to newest: #25, #26 and #27. Each file holds several channels’ partitions in token order, and channel 123 appears as one contiguous fragment in each: messages 1000 to 1180 in #25, 1181 to 1240 in #26, 1241 to 1950 in #27. Inside #27 the promoted index samples offsets within the fragment: message 1420 at plus 64 KB, 1600 at plus 128 KB, 1780 at plus 192 KB. The key cache holds three entries for this one partition, one per file, each pointing at the start of that file’s fragment: byte 12,880 in #25, 30,114 in #26, 48,392 in #27.
One partition, three flushes — contiguous inside each file, scattered across files Byte offsets are illustrative.

This is exactly why the read path (step 4/5) has to open all N SSTables and merge — not because any single file is disorganized, but because the partition's history is spread across files created at different times.

Large Partitions Within a Single SSTable: the Promoted Index

If one flush's fragment for a partition is itself large (a mega-channel with thousands of messages in one flush), Cassandra doesn't force a linear scan from the partition's start. It builds a promoted index — a sampled mapping of clustering-key ranges to byte offsets within that partition's block. The key cache gets you to the start of the fragment; the promoted index then narrows further to the right sub-range, avoiding a full scan.

  • Guarantees: A key-cache hit removes the index search for that file; within a file, the promoted index bounds how much of a large fragment is scanned.
  • Does not guarantee: Fewer files. The key cache makes each of the N opens cheaper; it does nothing about N itself.

Step 3 — Row Cache

The row cache caches the entire deserialized row in memory. A row cache hit means zero disk I/O for that partition. Sounds ideal, but:

  1. The row cache is invalidated on every write to that partition. For write-heavy tables, the row cache becomes useless — every write blows the cache for that row.
  2. It consumes JVM heap, which competes with memtable memory.

Row cache is only useful for read-heavy, rarely-updated reference data. For most tables, it is disabled.

  • Guarantees: On a hit, the whole partition is served from memory with zero disk I/O.
  • Does not guarantee: A useful hit rate on any table that is written to — each write invalidates the entry, and the heap it occupies is taken from the memtable.

Steps 4 & 5 — SSTable Reads and Merge

If all caches miss, Cassandra performs a binary search on the SSTable's on-disk index to find the relevant data pages, then reads them from disk.

It's a Merge, Not a Sort

Every SSTable is already sorted by partition key and clustering key, and so is the memtable. The read doesn't gather rows and re-sort them in memory — it opens a sorted iterator on each source and does a streaming k-way merge, picking the highest-timestamped version of each cell as it goes. That's much cheaper than sorting, and it's precisely why SSTables are kept sorted in the first place.

The real cost isn't CPU — it's the fan-out: N candidate SSTables means up to N file opens, N index lookups, and N disk seeks.

Everything upstream in the read path (bloom filters, timestamp skipping, key cache) exists to shrink N before disk is touched, and the compaction strategy (Part 6) is what bounds N between reads.

LeverWhat it does to the fan-out
Bloom filter (§2)Removes files that don't hold the partition at all
Min/max timestamp & clustering metadata (§2)Removes files that hold the partition but not the queried slice
Key cache (§3)Leaves N unchanged; removes the index lookup from each of the N
Compaction strategy (Part 6)Bounds N itself, between reads, by rewriting fragments together
  • Guarantees: Each cell resolves to its highest-timestamped version across every source, in a single streaming pass over already-sorted inputs.
  • Does not guarantee: That highest-timestamp means most recent in real time — the merge trusts the timestamps it's given (see §7, failure mode 2).

The Worst-Case Read Scenario

Worst case: a row that has been updated many times AND partially deleted with tombstones, and compaction has not run recently.

  1. Many SSTables → many file opens and seeks.
  2. Many tombstones → each tombstone must be evaluated to determine if underlying data is deleted.
  3. If tombstones have not been garbage-collected yet (gc_grace_seconds not elapsed), they must still be read and processed.
  • Guarantees: Correct results — the read still evaluates every version and every tombstone it finds.
  • Does not guarantee: Stable latency. The same query on the same table can be 100× slower depending purely on how far compaction is behind.

Tombstones: Why Deletes Cannot Be Real Deletes

In a leaderless, multi-replica system, a real delete is dangerous. There are two distinct ways it goes wrong.

Failure Mode 1: A Real Delete Leaves No Evidence

Imagine deletes were literal erasures — no marker left behind:

TimeReplica AReplica BReplica C
T1writes Rwrites Rwrites R
T2delete arrives, row eraseddelete arrives, row eraseddown, misses it
T3(has nothing)(has nothing)back online, still has R@T1

A quorum read hits A and C. A says "nothing." C says "R, written at T1."

"Nothing" isn't a version — it's missing information.

A real delete erased the row without leaving any timestamped record that a delete happened. Cassandra can't compare "nothing" against "R@T1" on timestamps, because there's nothing to compare. The only real data found anywhere is C's stale row, so that's what gets returned — and Cassandra read-repairs it back onto A and B, actively re-spreading deleted data across the cluster. The old data wins by walkover, not by beating anything in a comparison.

Failure Mode 2: Clock Skew Defeats the Timestamp Comparison

This one exists even with tombstones, because a tombstone is just another timestamped write compared the same way as any other.

  1. C has R@T1 (real wall-clock time: yesterday).
  2. The key is deleted and rewritten as R2@T3 (real wall-clock time: today), reaching A and B while C is down.
  3. C's clock (or the original writer's clock) was running fast when R@T1 was written, so its logical timestamp is actually 500, while the legitimately later write's logical timestamp is only 400.
  4. A read compares A's R2@400 against C's R@500. Numerically 500 > 400, so the stale row wins, even though it happened first in real time.

Tombstones don't fix this by themselves — it's why Cassandra deployments need NTP-synced clocks across nodes. If clocks are skewed, a tombstone can lose a comparison the same way a stale row can.

The Solution: Tombstones

Deletes are written as tombstones — a special marker that says "this key was deleted at timestamp T." The tombstone is replicated to all nodes just like a write (it's the same append-only write path — see Part 4 §5). It wins over any data with a lower timestamp. The actual removal of the tombstone (and the data it covers) is deferred to compaction, but only after gc_grace_seconds has elapsed — enough time for a down replica to have received the tombstone through repair.

gc_grace_seconds default10 days (864,000 seconds)
Consequence 1Tombstones persist for at least 10 days.
Consequence 2Any replica that was down for more than 10 days and never repaired before gc_grace_seconds passed may resurrect deleted data.
  • Guarantees: A delete is a versioned fact that beats any older write in a timestamp comparison, on every replica it reaches, for at least gc_grace_seconds.
  • Does not guarantee: Correctness under clock skew, or for a replica left unrepaired past gc_grace_seconds. Both resurrect deleted data.

Tombstone Accumulation Pathology

If you use Cassandra for a workload with many deletes (or TTL-based expiry, which uses tombstones internally), and compaction does not keep up, tombstones accumulate in SSTables.

What Happens During a Read with Heavy Tombstones

  1. Cassandra reads through tombstones to verify they are not covering live data.
  2. If a single partition has hundreds of thousands of tombstones, the read must scan all of them.
  3. By default, Cassandra logs a warning at 1,000 tombstones per read and throws a TombstoneOverwhelmingException and aborts the read at 100,000.
Setting (cassandra.yaml)DefaultEffect
tombstone_warn_threshold1,000Logs a warning for the read
tombstone_failure_threshold100,000Throws TombstoneOverwhelmingException, aborts the read

How to Avoid It

  1. Use TWCS compaction for time-series data where old data expires — TWCS compacts and drops entire SSTables at once when their time window closes, eliminating tombstones without accumulation.
  2. Design data models where you delete entire partitions rather than individual rows (partition-level deletes are more efficient).
  3. Set a TTL at the table level for data that should expire (default_time_to_live).
  4. Monitor tombstone counts with nodetool cfstats (named nodetool tablestats in current releases; cfstats remains an alias) and set alerts before the threshold is hit.
  • Guarantees: A hard ceiling: no single read will scan more than tombstone_failure_threshold tombstones — it fails first.
  • Does not guarantee: That the data is still readable. The ceiling protects the node's heap, not your query — past it, the read is aborted, not degraded.