Write Path and Commit Log
What You'll Learn
You'll understand how Cassandra (and similar wide-column stores) ensure durability by logging every write to disk before acknowledging success.
The Write Path Architecture
When a write request arrives at a Cassandra node, it follows a two-step durability guarantee before responding to the client:
-
Commit Log (Append-Only Disk Write): The write is immediately appended to a sequential log file on disk. This is extremely fast because it's a pure append operation—no seeking, no updates, just writing to the end of a file.
-
Memtable (In-Memory Buffer): Simultaneously, the write is also stored in an in-memory structure called a memtable. This is a sorted data structure that lives in RAM for fast access.
Only after both steps succeed does Cassandra acknowledge the write to the client.
Why This Design?
Think of the commit log like a diary: even if your computer crashes, you can replay the diary entries to restore your state. The memtable is your working memory—fast but volatile. By writing to both, Cassandra gets speed (in-memory) and safety (on-disk log).
Eventually, when a memtable fills up, it's flushed to disk as an SSTable (Sorted String Table), a permanent, immutable file. After the flush completes, the corresponding commit log entries can be safely discarded since the data is now durably stored in SSTables.
Recovery Scenario
If a node crashes before a memtable flush, Cassandra replays the commit log on restart to rebuild any lost in-memory data. No writes are lost.
Key Takeaway: Cassandra's write path writes to a commit log (disk) and memtable (memory) simultaneously, ensuring durability while maintaining high write throughput before later flushing to SSTables.