SD System Design In Depth
0%
lesson system-designstorage-engines

Log-structured storage

Module 2.3: Storage Engine Internals & Blob Systems Updated Sep 17, 2026
📄 Cheat Sheet
Log-Structured File Systems
David Evans Log-Structured File Systems Watch on YouTube ↗

A crisp university lecture on the Log-Structured File System: why appends beat in-place writes, and why the segment cleaner is the hard part.

0:00 / --:--

The Core Thesis of Log-Structured Systems

In 1991, Mendel Rosenblum and John Ousterhout published the seminal paper on Log-Structured File Systems (LFS). Their core thesis remains the foundation of high-performance database engineering today: disks handle large sequential writes far more efficiently than small random ones. By transforming all updates, deletes, and insertions into a single append-only sequential log, write performance approaches theoretical hardware limits.

Log-Structured Write Flow

flowchart LR Writes["Random Application Writes: (K1, V1), (K8, V2), (K3, V3)"] --> AppendBuffer["In-Memory Buffer / Memtable"] AppendBuffer -->|"Sequential Flushes"| LogSegment1["Log Segment 001.log (Immutable)"] AppendBuffer -->|"Sequential Flushes"| LogSegment2["Log Segment 002.log (Immutable)"] AppendBuffer -->|"Active Tail"| ActiveLog["Active Segment 003.log (Append Only)"]

The Fundamental Challenge: The Cleaner & Space Reclaim

Because every update appends a new record and every delete appends a tombstone, the log grows without bound until it is cleaned. A log-structured engine requires a background Cleaner / Compaction Engine:

  1. The cleaner selects cold or fragmented log segments.
  2. It reads the segment into RAM and identifies the latest valid version of each key by consulting an index.
  3. It discards overwritten values and tombstones.
  4. It writes the active surviving records into a new, contiguous log segment and unlinks the old files.

Worked example: the cost of cleaning

The LFS paper models cleaning with segment utilization u, the fraction of a segment that is still live when the cleaner picks it. To free one segment's worth of space, the cleaner reads the whole segment (1), writes back the live part (u), and gains room for 1 - u of new data. The paper's write cost, total bytes moved per byte of new data, is 2 / (1 - u).

Utilization of cleaned segmentsWrite costInterpretation
0.22.5Cheap: mostly garbage
0.54Moderate
0.810Expensive: 10 bytes of I/O per byte written
0.920Near-stall territory

This is why cleaning policy matters. LFS found that a cost-benefit policy (prefer segments with lots of free space and old, stable data) beats greedy "emptiest segment first", because cold data stays put and hot data dies quickly in its own segments.

In-place versus log-structured

PropertyUpdate in placeLog-structured
Write patternRandomSequential appends
Crash recoveryWAL replay plus torn-page protectionReplay from last checkpoint in the log
Space overheadLowDead versions until cleaned
Background workCheckpointingCleaning or compaction, often the bottleneck
Read localityStable, by key or pageBy write time unless compacted

Where the idea shows up

  • SSD firmware: the flash translation layer is itself log-structured, with its own garbage collector.
  • Kafka: append-only segments; retention deletes whole old segments, and log compaction keeps only the latest record per key.
  • LSM-trees (RocksDB, Cassandra, Bigtable): the log becomes sorted runs, and cleaning becomes compaction.
Check yourself Question 1 of 3
What the cleaner keeps recall
From: The Fundamental Challenge: The Cleaner & Space Reclaim

When the cleaner processes a segment, how does it decide which records to copy forward?

Key Takeaways

Log-structured storage converts all random updates into high-throughput sequential disk appends.
Deletions and updates leave obsolete versions in place, requiring background compaction to reclaim space.
LFS principles power modern storage engines including RocksDB, Bigtable, Kafka, and Cassandra.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue