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
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:
- A
QUORUMread at RF=3 contacts exactly 2 replicas, not all 3. - 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.
- 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 |
|---|---|
| Granularity | Per-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 saves | The 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:
| Step | What happens |
|---|---|
| Bloom filter | Checks 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 cache | For 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 cache | Caches 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.
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:
- 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.
- 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.
| Lever | What 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.
- Many SSTables → many file opens and seeks.
- Many tombstones → each tombstone must be evaluated to determine if underlying data is deleted.
- If tombstones have not been garbage-collected yet (
gc_grace_secondsnot 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:
| Time | Replica A | Replica B | Replica C |
|---|---|---|---|
| T1 | writes R | writes R | writes R |
| T2 | delete arrives, row erased | delete arrives, row erased | down, 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.
- C has R@T1 (real wall-clock time: yesterday).
- The key is deleted and rewritten as R2@T3 (real wall-clock time: today), reaching A and B while C is down.
- 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 only400. - 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 default | 10 days (864,000 seconds) |
|---|---|
| Consequence 1 | Tombstones persist for at least 10 days. |
| Consequence 2 | Any 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
- Cassandra reads through tombstones to verify they are not covering live data.
- If a single partition has hundreds of thousands of tombstones, the read must scan all of them.
- By default, Cassandra logs a warning at 1,000 tombstones per read and throws a
TombstoneOverwhelmingExceptionand aborts the read at 100,000.
Setting (cassandra.yaml) | Default | Effect |
|---|---|---|
tombstone_warn_threshold | 1,000 | Logs a warning for the read |
tombstone_failure_threshold | 100,000 | Throws TombstoneOverwhelmingException, aborts the read |
How to Avoid It
- Use
TWCScompaction 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. - Design data models where you delete entire partitions rather than individual rows (partition-level deletes are more efficient).
- Set a TTL at the table level for data that should expire (
default_time_to_live). - Monitor tombstone counts with
nodetool cfstats(namednodetool tablestatsin current releases;cfstatsremains an alias) and set alerts before the threshold is hit.
- Guarantees: A hard ceiling: no single read will scan more than
tombstone_failure_thresholdtombstones — 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.