The LSM Tree and the Wide Row

A companion to Part 4b — Memtable Anatomy, which zooms into the memtable while it is still in memory. This one answers a different question, and it is the question that trips up almost everyone who already understands LSM trees: where on disk does a partition actually live? The consequence worth internalizing is that it doesn't live anywhere — a partition is a contiguous key-range in a sorted file, reassembled on demand, and every operational property of the "wide row" (hot nodes, size ceilings, bucketing) falls out of that.

The short answer is that it doesn't live anywhere. A partition is not a container. It is a contiguous key-range in a sorted file, reassembled on demand. Once that clicks, the phrase "wide column store" stops being mysterious — it turns out to be a naming convention sitting on top of the ordinary sorted-KV LSM you already know.

The Key Shape Is the Whole Story

Cassandra is a sorted key-value store where the key is (hash(partition_key), clustering_key). Everything else — wide rows, wide columns, column families — is vocabulary describing what that key shape implies.

The two halves of the primary key do completely different jobs, and this asymmetry is the only part that isn't vocabulary:

PRIMARY KEY ((channel_id), message_id). The partition key channel_id is hashed with murmur3 into a token; the token decides which node holds the data and which contiguous block it occupies in each file. The clustering key message_id is kept as its real value and decides the order of rows inside that block. In one SSTable sorted by token then message_id, ch17, ch42 and ch99 each form one block, and inside the ch42 block the rows m1, m3, m6 sit in message_id order.
TL;DR · One primary key, two jobs — the hash places the block, the real value orders inside it
channel_id (partition key)message_id (clustering key)
Stored asmurmur3 hash → token (the file is ordered by the token; the raw key bytes are stored alongside it — see §4's key map)the real value, in true sort order
Decideswhich node, and which contiguous block within each filethe order inside that block
Buys youeven spread across the cluster; one seek reaches the block within a given filecheap ORDER BY, LIMIT, and range slices
Costs youno range scans across it — channel_id > 40 is not a queryonly works within one partition

Because the partition key is the prefix of the sort key, every row sharing it necessarily lands in one unbroken run. That's the whole mechanism: co-location is a free side effect of sorting, not a feature anyone implemented.

Two caveats that the rest of this document unpacks:

  1. "Together" is per-file. Contiguous within one SSTable; fragmented across N SSTables, because a sealed file is never edited. A read is N seeks and an N-way merge. Compaction shrinks N, never to 1 for a live partition. (§4)
  2. The name is historical; three consequences are not. A row has no fixed width (unwritten cells cost nothing). The partition is the indivisible unit of distribution and atomicity — never split across nodes, which is why a hot channel is a hot node. And it therefore has a size ceiling, which is why you bucket. (§6, §7)

Running example is the same Discord-style table used in Part 4b and Part 5 — Read Path:

CREATE TABLE messages (
  channel_id bigint,
  message_id bigint,   -- Snowflake: globally unique, time-ordered
  author     text,
  content    text,
  PRIMARY KEY (channel_id, message_id)
);

The Rule Everything Follows From

A file that has been written to disk is never edited again.

That is the entire LSM premise, and every property below is a consequence of it.

Edit in place — cost grows with the data

Editing a record in place means: locate it on disk, read the page, modify it, write it back, possibly split. That cost is paid on every write.

Append a new file — flat cost

Appending a whole new file means: dump bytes sequentially. That cost is the same no matter how much data already exists.

So the LSM never edits. It only ever creates new files, and pays the tidying cost later, in bulk, in the background.

  • Guarantees: Write cost that does not depend on how much data already exists — no page lookup, no read-modify-write, no split.
  • Does not guarantee: That the tidying cost disappears. It is deferred into background compaction, and until compaction runs, reads pay for the untidiness.

Three Channels, Six Messages

Six messages arrive interleaved across three channels, in wall-clock order. message_id is a Snowflake, so it increases globally:

message_idchannelauthorcontent
m1ch42alice"hey"
m2ch99dave"yo"
m3ch42bob"sup"
m4ch17carol"hi"
m5ch99erin"lol"
m6ch42alice"brb"

Each one goes to the commit log, then into the memtable. The memtable is sorted by token(channel_id), then by message_id. Assume the hashes happen to order the channels ch17 < ch42 < ch99.

Six messages arrive interleaved in wall-clock order: m1 for ch42, m2 for ch99, m3 for ch42, m4 for ch17, m5 for ch99, m6 for ch42. The memtable sorts by token then message_id, so they come out grouped: ch17 then m4; ch42 then m1, m3, m6; ch99 then m2, m5. The flush writes that order into SSTable-1, which is sealed and never edited again.
Interleaved in, grouped out — nobody wrote grouping logic, sorting did it

memtable (after m1–m6)

memtable
  ch17 → m4
  ch42 → m1, m3, m6
  ch99 → m2, m5

after the flush

SSTable-1    ← written once, never touched again
  ch17 → m4
  ch42 → m1, m3, m6
  ch99 → m2, m5

Memtable fills, flushes (above). The next six messages repeat the cycle:

The next six messages, m7 to m12, fill a fresh memtable which flushes into a new file, SSTable-2: ch17 then m9; ch42 then m7, m11; ch99 then m8, m10, m12. Writing m7 did not open, append to or rewrite SSTable-1, which stays sealed and read-only. After twelve messages ch42 already lives in two files.
The next batch is a new file — SSTable-1 is never reopened

Note what did not happen: writing m7 did not open SSTable-1, did not append to it, did not rewrite it. SSTable-1 was sealed at flush time and is now read-only forever.

  • Guarantees: Within any one flushed file, each channel's messages sit together, in message_id order, regardless of the order they arrived in.
  • Does not guarantee: That a channel's messages sit in one file. ch42 already lives in SSTable-1 and SSTable-2 after just twelve messages.

So Where Is the Channel?

Nowhere, as a single object. There is no folder, no file, no block called ch42. The channel's messages are spread across SSTable-1, SSTable-2, and the current memtable.

The channel becomes a single thing only when you ask for it:

ch42 has fragments in three places: m1, m3 and m6 in SSTable-1; m7 and m11 in SSTable-2; and m13 in the current memtable. Each fragment is contiguous and already sorted. A query zips them together in memory into m1, m3, m6, m7, m11, m13 — that union is "the channel", it exists only while the query runs, and every query rebuilds it.
"The channel" is a zip of fragments, rebuilt by every query

Each line in that diagram is one contiguous fragment. The channel is the union of the fragments, and that union exists only in memory, only while the query runs. Then it's gone again — every query rebuilds it.

  • Guarantees: A read sees the channel as one ordered sequence, assembled by a streaming merge that can stop early on LIMIT.
  • Does not guarantee: That the assembled channel persists anywhere. Every query rebuilds it from the fragments.

Why the Fragments Are Contiguous: the Partition Key Is a Sort-Key Prefix

This is the mechanical insight the rest of the model rests on.

It is tempting to picture the LSM as sorted by message_id. It isn't. The sort key is the whole primary key:

( token(channel_id) , message_id )partition key (hashed) · clustering key (real value)

One flat, sorted keyspace. Every row in every SSTable is one entry in that map:

keyvalue
(token 0x1A, ch17, m4){author: carol, content: "hi"}
(token 0x5C, ch42, m1){author: alice, content: "hey"}
(token 0x5C, ch42, m3){author: bob, content: "sup"}
(token 0x5C, ch42, m6){author: alice, content: "brb"}
(token 0x7F, ch99, m2){author: dave, content: "yo"}
(token 0x7F, ch99, m5){author: erin, content: "lol"}

That is a plain sorted KV store. Nothing Cassandra-specific yet.

Because channel_id is the prefix of that sort key, every row belonging to ch42 necessarily lands in one unbroken run. Sorting by (channel, message) groups by channel for free. Which gives the actual definition:

A partition is a contiguous key-range in the sorted file, identified by a key prefix.

Not a container. Not an object. A range. That is why "where does the partition live" has no answer — the question assumes a thing that doesn't exist.

And So the Read Is a Bounded Range Scan

"Last 50 messages in ch42" becomes:

scan [ (0x5C, ch42, +∞) → (0x5C, ch42, -∞) ]   in every candidate file

One contiguous slice out of each file, then zip the slices. Exactly the LSM merge you already know, bounded to a key range instead of running over the whole file. The bloom filter and each SSTable's min/max bounds throw out most files before any I/O happens at all — see Part 5 — Read Path for that machinery in detail.

Be Precise About What "Contiguous" Claims

Contiguity is a per-file property, and only that:

Nothing routes a partition to "its" SSTable. The token decides which node owns the data, but on that node every write goes to the same memtable, and each flush writes out whatever happened to be in memory at that moment:

10:00  write ch42 m1   -> memtable
10:01  write ch42 m3   -> memtable
10:02  write ch42 m6   -> memtable
       ... memtable fills, flushes ...       -> SSTable-1  (ch42: m1, m3, m6)
11:30  write ch42 m7   -> new memtable
11:31  write ch42 m11  -> new memtable
       ... flushes ...                       -> SSTable-2  (ch42: m7, m11)

ch42 now lives in two files. Each file is shared by many partitions, and the sort order is the only thing that keeps any one partition's slice together:

Within one SSTable: yes

The file was written in a single pass from one memtable flush (or one compaction), so all of the partition's data as of that moment is serialized together, sorted by clustering key, as one unbroken block. One seek gets you to it.

Across SSTables: no

Each later flush that touched ch42 produced another contiguous fragment in another file, holding a different slice of message_ids. The partition's full history is spread over N files.

Two SSTables, each sorted by token then message_id. In each, ch42 is one contiguous block between ch17 and ch99: m1, m3, m6 in SSTable-1 and m7, m11 in SSTable-2. A read of ch42 does one seek per file to reach its block, reads one slice from each, and streams them through a 2-way merge into m1, m3, m6, m7, m11. N fragments cost N seeks plus an N-way merge; compaction shrinks N but never to 1 for a partition still being written.
Contiguous within each file, fragmented across files — here N = 2

So a read of ch42 is N seeks and an N-way merge, not one seek — one seek per surviving fragment, then zip. The merge is not there because any single file is disorganized; it is there because the partition's history was written at N different times, and the "never edit a file" rule forbids folding the new data back into the old file.

That merge cost is precisely what Part 6 — Compaction exists to bound: compaction rewrites overlapping SSTables into fewer files, shrinking N. It never reaches 1 for a partition still being written to. How small N stays depends on the strategy:

StrategySSTables one partition typically spansWhy
LCS (leveled)A small, bounded number: the L0 files not yet compacted, plus at most one per level above thatSSTables within each level above L0 have non-overlapping key ranges
STCS (size-tiered)Can be many between compactionsIt merges files by size, not by key range, so overlapping fragments pile up
TWCS (time-window)About one per time window the partition was written inEach closed window is compacted into one file; works well when queries hit recent windows

The trade-offs behind each are in Part 6 §2 — Compaction Strategies.

Two Orderings, Two Different Guarantees

Sorted byWhat that buysWhat it costs
Partition keytoken = murmur3(channel_id)Even spread across nodes; one seek reaches the whole slice (per file — see above)Channels sit in pseudo-random order, so you cannot range-scan across partition keys
Clustering keyreal value of message_idORDER BY, LIMIT, and range slices inside a partition are cheap sequential readsOnly works within one partition
  • Guarantees: Within any one SSTable, a partition is a single unbroken block sorted by clustering key — one seek reaches it.
  • Does not guarantee: One seek per partition read. The cost is one seek per surviving fragment plus an N-way merge, and compaction can shrink N but not to 1 while the partition is still being written.

Zoom In One Level: What Is m1, Physically?

Everything above treated m1 as an atom. It isn't. Cassandra stores each column value as its own independent unit, with its own write timestamp. So this:

ch42 → m1, m3, m6

is really this:

The partition key ch42 holds rows m1, m3 and m6, but each row is not an atom: every column value is its own cell with its own write timestamp. m1 is author = alice and content = "hey", both at T1; m3 is author = bob and content = "sup" at T2; m6 is author = alice and content = "brb" at T3. Six small cells hang off the one key.
A row is not an atom — each column value is its own timestamped cell

Same picture, one level deeper. Six small values, all hanging off the key ch42.

Each of those values is a cell. In pre-CQL Cassandra vocabulary, a cell was called a column.

Where "Wide Column Store" Comes From

Now just read §5 out loud: one key (ch42), with six columns underneath it.

m7 arrives → eight columns. A busy channel → three million columns. There is no fixed number, because columns are produced by writing data, not by declaring schema.

Early Cassandra called that key-plus-its-cells a row. Since the column count had no upper bound, it was a wide row. A database built on that idea is a wide column store.

That is the entire etymology. Nothing cleverer than that.

Compare the two shapes for the same six messages:

Left, relational: six rows by four fixed columns, channel_id, message_id, author, content, one row per message. Right, wide column: three keys. ch17 holds 2 cells from m4; ch42 holds 6 cells from m1, m3 and m6; ch99 holds 4 cells from m2 and m5. A new message is a new row on the left and more cells on an existing key on the right.
The same six messages, two shapes — fixed-width rows vs. keys with unbounded cells
RelationalWide column
6 rows × 4 fixed columns3 rows, with 6 / 2 / 4 columns (ch42 / ch17 / ch99)
columns fixed by schemacolumns unbounded, created by writing
a new message = a new rowa new message = more columns on an existing row

The Vocabulary Collision (This Is the Confusing Part)

"Row" means two different things depending on which era is talking. Given:

ch42 → m1.author, m1.content, m3.author, m3.content, m6.author, m6.content

How many rows is that?

Old storage-engine answer: one

One key, six columns. One wide row.

CQL answer: three

m1, m3, m6 — three rows in a table.

Identical bytes. Two vocabularies. Modern docs resolved it by renaming the old "row" to partition:

Old termModern termIn the example
row / wide rowpartitionthe whole ch42 → block
columncellone value, e.g. m1.author = alice
—rowone message: m1 and its cells

So "Cassandra is a wide column store" means: the thing I call a row can hold an unbounded number of columns. Translated to today's words: a partition can hold a very large number of rows.

CQL then puts a table-shaped view over it:

On disk, one wide row: the key ch42 followed by six cells, m1.author alice, m1.content hey, m3.author bob, m3.content sup, m6.author alice, m6.content brb. CQL presents the same bytes as a three-row table with columns channel_id, message_id, author and content: ch42 m1 alice hey, ch42 m3 bob sup, ch42 m6 alice brb. Each pair of cells becomes one CQL row; the old “row” is now called a partition.
CQL’s three rows are one wide row underneath — same bytes, new names

Same bytes on disk. The wide row is still there; it's just called a partition now, and what CQL shows as three rows is one wide row underneath.

  • Guarantees: Unwritten cells cost nothing on disk — a row has no fixed width, and rows in one partition may populate entirely different column subsets.
  • Does not guarantee: Schema-free columns. In CQL every column name must be declared; only the number of rows per partition is unbounded.

Why Any of This Matters Operationally

The wide row is the unit of several things at once, and this is where the terminology stops being trivia:

The partition is the unit of…Consequence
DistributionThe whole partition lives on the same replica set. ch42 with 3M messages is not split across nodes — one node owns all of it. A hot channel is a hot node.
Storage localityContiguous within each SSTable → one seek per fragment. A partition spread across 8 SSTables costs 8 seeks and an 8-way merge — still far cheaper than one read per message, which is the point.
Atomicity & isolationA batch touching only ch42 is atomic and isolated. A batch touching ch42 and ch99 is neither. (Precision: a multi-partition logged batch is still eventually all-or-nothing via the batchlog, but it is never isolated — readers can see it half-applied; an unlogged multi-partition batch has neither property.)
Repair & compaction workCompaction rewrites whole partitions; repair streams them. Big partition = expensive everywhere.

Which is exactly why Discord buckets:

PRIMARY KEY ((channel_id, bucket), message_id)   -- bucket ≈ 10 days

That deliberately caps how wide the row can get, at the cost of the query needing to know which bucket(s) to hit. Same trade appears for IoT, time-series, and activity feeds — see Part 7 — Data Modeling §"bucket by time" and Part 9 — Operations on unbounded-partition symptoms.

  • Guarantees: Everything about one partition — placement, locality, single-partition batch atomicity and isolation — is decided by one key and lives on one replica set.
  • Does not guarantee: That the partition stays a manageable size. Nothing splits it for you; the ceiling is enforced only by your choice of partition key (e.g. adding a time bucket).

The Whole Thing in One Paragraph