Write Path Internals

Part 3 covered how many copies of a write exist and how they reconcile. This part is what one replica does with a write once it lands: append it to a log, put it in a sorted in-memory structure, acknowledge the client, and flush to an immutable file later. The consequence worth internalizing is that every mutation is an append — inserts, updates, and deletes are the same physical operation — which is why write throughput barely moves with the insert/update mix, and why all of the cost shows up later in reads and compaction instead.

The Full Write Path

A client sends a write to a coordinator, which hashes the partition key, looks up the owning replicas in its local ring map and forwards the write to each of the RF replicas. On each replica step 1 appends the mutation to the commit log on disk, which is sequential and durable, and step 2 inserts it into the memtable in memory, which is sorted. The replica acknowledges after those two steps, and the coordinator acknowledges the client once enough replicas have. Step 3, flushing the memtable to an immutable SSTable on disk, happens later on Cassandra’s schedule, off the client’s path.
Two cheap steps, then the ACK — the flush to disk happens later

How the Coordinator Knows Where to Forward

Every node keeps a live, gossip-synchronized map of token-range ownership (see Part 2 — the coordinator node and the gossip section alongside it). The coordinator hashes the partition key, looks up the owning replicas in that local map, and sends the write directly to them.

No lookup service. No round trip to ask anyone. Correctness depends only on the coordinator's ring map being accurate — never on the coordinator itself holding the data.

That's what makes "any node can be a coordinator" workable rather than merely convenient: a node that owns none of the relevant data is still a perfectly correct router for it.

  • Guarantees: An acknowledged write is recoverable — it is in the commit log on disk before the client hears anything, so a crash immediately after the ACK loses nothing.
  • Does not guarantee: That the write is in an SSTable. Between the ACK and the flush, durability rests entirely on the commit log and on replay working correctly at startup.

Stage 1 — Commit Log

What it isAn append-only, sequential write to disk. Every incoming write is logged here before anything else happens.
Problem it solvesCrash recovery. If the node dies after the log write but before the memtable is flushed, Cassandra replays the log on restart and recovers every acknowledged write.
The trade-offEvery write hits disk twice — once here, once at flush. The log write is nearly free because it is purely sequential: no seeking.

Without the commit log, everything sitting in the memtable is lost on a crash — which, given the memtable is where writes live between the ACK and the flush, means losing writes you already told the client had succeeded.

  • Guarantees: Every acknowledged write survives a process crash and is replayed at startup.
  • Does not guarantee: Survival of the disk itself. The commit log is a node-local durability mechanism; surviving hardware loss is replication's job (Part 3), not the log's.

Stage 2 — Memtable

What it isAn in-memory structure, sorted by partition key and clustering key, accumulating writes after they've been committed to the log.
Problem it solvesRandom I/O. Writing individual rows to random positions in an on-disk structure is brutal on spinning disks and still costly on SSDs.
The trade-offMemtable contents are lost on crash — the commit log covers that. But a larger memtable means longer restart recovery (more log to replay) and higher peak memory.

What Triggers a Flush

TriggerWhy it exists
Memtable size exceeds memtable_heap_space_in_mbThe ordinary case — bound memory use.
A manual nodetool flushOperator-driven, typically before maintenance or a snapshot.
A commitlog segment fills and needs recyclingCassandra can't discard a log segment while data it covers is still only in memory — so it must flush first.
Graceful node shutdownAvoids a long replay on the next startup.
  • Guarantees: Data leaves memory to disk in sorted order, in a single sequential pass, regardless of the order it arrived in.
  • Does not guarantee: Bounded restart time. Recovery is proportional to unflushed commit log, so a big memtable directly buys a slower startup.

Stage 3 — SSTable

An SSTable (Sorted String Table) is an immutable, sorted, on-disk file holding data flushed from the memtable. Each flush produces a new one. It's written once, in a single linear pass through memory, and never modified again.

Why Immutability?

Modifying an on-disk sorted file in place is both expensive and dangerous:

  1. Inserting a row in the middle of a sorted file would require shifting everything after it.
  2. A partially written file during a crash would leave corrupted data with no easy recovery path.
  3. Immutability makes crash recovery trivial — a partially written SSTable is simply discarded. There is nothing to repair, because nothing valid was overwritten.
  • Guarantees: A file that exists is complete and internally consistent. Recovery never has to reason about a half-modified file.
  • Does not guarantee: That a partition lives in one file. Its history is spread across every SSTable that was open when part of it was written — which is what the read path has to merge.

Updates and Deletes Are Both Writes

An "update" is a new write of the new value with a higher timestamp. The old value stays in an older SSTable until compaction resolves it. A "delete" is also a write — a marker called a tombstone (covered in depth in Part 5). Nothing is actually deleted at write time.

An Update Is an Append — So Updates Are as Fast as Inserts

UPDATE and INSERT in CQL compile to the same physical operation: an upsert.

INSERT

INSERT INTO playback
  (user_id, title, position)
VALUES ('u1', 'Arcane', '1:42:07');

UPDATE — identical write path

UPDATE playback
  SET position = '1:42:07'
WHERE user_id='u1' AND title='Arcane';

Either way: append to the commit log, insert cells into the memtable, done. Nothing reads the old value, nothing locks a row, nothing seeks to where the old data lives on disk. The old version keeps sitting in some older SSTable, now shadowed by a cell with a newer timestamp.

Two panels. Left, a B-tree store: page 42 on disk holds position 1:40:00; the update seeks to that page, latches it, reads it and rewrites it, so the same page now holds 1:42:07 — one seek, one read, one write, with the row latched throughout. Right, Cassandra: the update appends to the commit log and inserts a brand-new cell, position 1:42:07 at timestamp t2, into the memtable. The old cell, 1:40:00 at t1, stays untouched in SSTable-1. Nothing is sought, locked or read; a later read keeps the cell with the higher timestamp, so t2 shadows t1.
The same update: a B-tree rewrites the page, Cassandra adds a newer cell

Reads reconcile by merging the memtable plus every candidate SSTable and keeping the highest-timestamped value per cell — last-write-wins. Compaction later discards the shadowed versions physically.

Contrast with a B-tree store like InnoDB, where an update means: find the page, latch it, modify in place, write it back. Cassandra turned every mutation into a sequential log append and deferred the reconciliation cost to reads and compaction. That's why its write throughput is high regardless of the insert/update mix.

Real Update-Heavy Use Cases

Not just append-only ones — these are genuinely overwrite-shaped workloads that Cassandra handles well.

Use caseShape
Netflix playback position PRIMARY KEY ((user_id), title) — partition key user_id, clustering column title. Each show a user watches is its own row inside that user's partition. While you're watching, the position cell is overwritten every few seconds; switching shows writes to a different clustering row in the same partition, so shows never clobber each other. Last-write-wins is semantically perfect here: the latest position is by definition the right one.
Discord message edits An edit is an upsert to the same (channel_id, bucket, message_id) row; the new content cell shadows the old. The append-heavy table handles edits for free.
Amazon shopping cart The founding use case of the Dynamo paper on Cassandra's ancestry tree. A rejected "add to cart" write is a lost sale, so availability trumps consistency: no single master to fail over, sloppy quorums, hinted handoff — the write succeeds even if the "right" replicas are down. Carts also tolerate the resulting eventual consistency because they're mergeable: "add item X" is commutative, so divergent replicas reconcile by unioning operations rather than picking one winner. A strict-consistency store would rather block or reject the write during a partition — exactly the wrong trade-off here.
Session state / presence / "last seen" Blind overwrites of a known key, at high sustained rate.

The Real Dividing Line

It is not append vs. update. It is whether the new value depends on the old value.

Fast — blind overwrite

"Position is now 1:42:07." The write carries everything it needs. As fast as an append, because the write path never has to know what it's replacing.

Slow — read-modify-write

"Increment this." "Update only if unchanged." Last-write-wins cannot express these. They need counter columns (a local read-before-write) or lightweight transactions (Paxos, ~4 network round trips, an order of magnitude slower — Part 8).

This is why the famous Cassandra use cases are all append- or blind-overwrite-shaped. It isn't that Cassandra can't update — it's that it can only update fast when the write doesn't need to know what it's replacing.

  • Guarantees: Constant-ish write cost regardless of whether a row is new, updated, or deleted — no read, no lock, no seek on the write path.
  • Does not guarantee: That the cost went away. Every shadowed version is still on disk, still merged on read, and still rewritten by compaction until it's finally dropped.

Write Amplification

Write amplification is the ratio of bytes written to disk per byte of user data. Cassandra's write path contributes in three places.

Commit log  the raw data, written sequentially1×
Memtable flush  the data written again, into its first SSTable1×
Compaction — STCS  worst case, data is rewritten once per tier as it cascadesO(log N)
Compaction — LCS  more rewrites, to maintain sorted order within each level~10×
Bar widths are illustrative — the point is the ratio, not the absolute figures.

Under STCS (Size-Tiered Compaction), in the worst case data is rewritten O(log N) times as it cascades through compaction levels. Under LCS (Leveled Compaction), write amplification is higher — on the order of 10× — because the leveled strategy does more rewrites to maintain sorted order within levels.

  • Guarantees: A floor of 2× — commit log plus initial flush — before compaction contributes anything at all.
  • Does not guarantee: Any ceiling. Total amplification is a property of the compaction strategy and the update rate, and under LCS on an update-heavy table it is unbounded in practice until compaction keeps up.