Course contentsShow
← Computer Science
Lesson 1741 of 2,87239. NoSQL and Modern DatabasesFree lesson

Read and Write Operations in Column Families

Learn how writes go to memory and commit logs, and how reads merge data from memory and disk-based SSTables.

Read and Write Operations in Column Families

You'll learn how column-family databases handle writes by splitting data between fast memory structures and durable logs, and how reads intelligently merge data from multiple sources.

How Writes Work: Memory First, Durability Always

When you write data to a column-family database (like Cassandra or HBase), the system performs two critical actions simultaneously:

  1. Append to the commit log — The write is immediately recorded to a durable, append-only file on disk. This ensures durability; if the server crashes, no data is lost.

  2. Write to an in-memory structure (memtable) — The data is also stored in a fast, sorted in-memory table. This makes recent writes immediately available for reads without touching disk.

Once the memtable grows beyond a threshold, it's flushed to disk as an immutable SSTable (Sorted String Table). The corresponding commit log entries can then be discarded.

Think of it like a restaurant order system: every order is written on a permanent receipt (commit log) and placed on the active cooking board (memtable). When the board fills up, completed orders move to archived records (SSTables).

How Reads Work: Merging Multiple Sources

Reading is more complex because your data might exist in multiple places:

  1. Check the memtable first — most recent writes live here
  2. Query SSTables on disk — older data lives in one or more immutable files
  3. Merge results — combine data from all sources, with newer entries overriding older ones

Since checking multiple SSTables is expensive, databases use bloom filters (compact data structures that quickly say "definitely not here" or "maybe here") to skip unnecessary disk reads.

Key Takeaway: Column-family writes achieve speed through memory buffering and durability through commit logs, while reads merge data from memory and multiple disk-based SSTables, using filters to minimize expensive disk access.