What are SSTables and how does the write path persist data?
Understand what SSTables are, how Cassandra's write path flushes memtables into immutable sorted files, and how updates, deletes and reads work.
Expected Interview Answer
SSTables (Sorted String Tables) are immutable, on-disk files that Cassandra creates when it flushes a memtable; they store rows sorted by partition and clustering key and, once written, are never modified.
The write path first appends the mutation to the commit log and updates the memtable in memory. When the memtable is flushed, its contents become one new SSTable plus supporting files: a partition index, a Bloom filter, and compression/statistics metadata. Because SSTables are immutable, updates and deletes are written as new versions (deletes use tombstones) in later SSTables rather than editing existing files. Reads merge data across multiple SSTables and the memtable, and background compaction later consolidates them.
- Immutability makes files simple, safe and cache-friendly
- Sorted layout enables efficient range scans
- Bloom filters skip SSTables that can't contain a key
- No in-place updates means no random-write contention
- Partition indexes speed up locating rows on disk
AI Mentor Explanation
An SSTable is like a printed, laminated scorecard from a finished match — sealed and never edited. If a correction is needed, you don't scratch the old card; you issue a fresh addendum card and readers combine both. Cassandra persists data the same way: each flush prints a permanent sorted SSTable, and later changes arrive as new cards rather than edits, with compaction eventually merging them into one clean sheet.
Step-by-Step Explanation
Step 1
Buffer in the memtable
Writes accumulate in the sorted in-memory memtable after being logged to the commit log.
Step 2
Flush to a new SSTable
When the memtable fills, its sorted contents are written once to a new immutable SSTable file.
Step 3
Build companion structures
Cassandra also writes a partition index, a Bloom filter, and compression/statistics metadata alongside the data file.
Step 4
Handle updates and deletes
Because SSTables never change, newer values and tombstones are written into later SSTables instead of edits.
Step 5
Merge on read and compaction
Reads merge the memtable and relevant SSTables; background compaction later consolidates SSTables and drops obsolete data.
What Interviewer Expects
- Definition of SSTable and its immutability
- That flushing a memtable creates an SSTable
- Awareness of the Bloom filter and partition index
- How updates/deletes are handled without in-place edits
- That reads merge multiple SSTables
Common Mistakes
- Claiming SSTables are mutable or updated in place
- Thinking one write equals one SSTable
- Forgetting the Bloom filter and index files
- Confusing an SSTable with the commit log
- Not knowing deletes create tombstones
Best Answer (HR Friendly)
“An SSTable is a permanent file Cassandra writes to disk when its memory buffer fills up; once written it is never changed. Any later edits or deletes go into new files, and Cassandra combines them when reading. This keeps writing simple and fast while staying reliable.”
Code Example
# After: nodetool flush keyspace1 users
# A single flush produces a set of immutable component files:
# md-1-big-Data.db <- the sorted row data
# md-1-big-Index.db <- partition index
# md-1-big-Filter.db <- Bloom filter
# md-1-big-Statistics.db <- metadata/statistics
# md-1-big-CompressionInfo.db
# Inspect an SSTable's contents as JSON:
sstabledump md-1-big-Data.db | head -n 40Follow-up Questions
- Why are SSTables immutable?
- What is a Bloom filter and how does it speed up reads?
- How does Cassandra read a row spread across many SSTables?
- What is a tombstone and why is it needed?
- How do the partition index and summary help locate data?
MCQ Practice
1. What does SSTable stand for?
SSTable stands for Sorted String Table — an immutable on-disk file storing rows sorted by key.
2. How are updates applied to an existing SSTable?
SSTables are immutable, so updates and deletes are written into newer SSTables and merged at read time.
3. Which structure lets Cassandra skip SSTables that cannot contain a key?
A Bloom filter is a probabilistic structure that tells Cassandra a key is definitely not in an SSTable, letting it skip that file.
Flash Cards
What is an SSTable? — A Sorted String Table: an immutable on-disk file of rows sorted by partition/clustering key, created when a memtable flushes.
Are SSTables mutable? — No. They are immutable; updates and deletes go into newer SSTables and are merged on read.
What files accompany an SSTable? — A partition index, a Bloom filter, and compression/statistics metadata alongside the data file.
How is a delete stored? — As a tombstone marker written to a new SSTable, indicating the data is removed until compaction purges it.