Databases 16 min read

How LSM Tree Overturned B-Tree: The 1996 Innovation Behind Modern Write-Heavy Databases

This article traces the origin of the Log-Structured Merge-Tree (LSM Tree) from a 1996 paper by Patrick O'Neil et al., explaining how its sequential-write, background-compaction design solved the random I/O bottleneck of B-Trees, enabling modern write-heavy systems like Cassandra, RocksDB, and Kafka.

dbaplus Community
dbaplus Community
dbaplus Community
How LSM Tree Overturned B-Tree: The 1996 Innovation Behind Modern Write-Heavy Databases

Background: An Era Crushed by Write Loads

In the early 1990s, relational databases dominated, with B-Tree indexes as the de facto storage standard from IBM's System R to MySQL InnoDB. However, write-intensive systems — telecom billing, banking transaction logs, early sensor data collection — struggled. Their workloads were append-heavy, massive in volume, required sustained stable writes, had relatively few reads, and ran on mechanical disks where random seeks were hundreds to thousands of times slower than sequential I/O. B-Tree updates inherently cause random I/O because each modification requires an in-place page write, often triggering page splits. Vendors optimized caches, prefetching, and disk schedulers, but these merely masked the structural problem: every write still paid a random I/O cost.

Patrick O'Neil, after work at Bell Labs, recognized that no amount of B-Tree tuning could eliminate this fundamental penalty for sustained high write loads.

Why Old Solutions Failed

B-Tree: Optimized for Reads, Pays for Writes

B-Trees guarantee O(log n) disk I/O for any record lookup, making reads efficient. But each insert or update may trigger an in-place modification or page split, forcing the disk head to jump across platters. Under heavy writes, throughput collapses.

Mitigations Only Masked the Problem

Write buffers, delayed flushes, and batch commits hid the issue but did not change the essence: data layout on disk was still dictated by business write order, not by the disk's preferred sequential pattern.

Hash Tables and Skip Lists: No Persistence Answer

Hash tables are fast in memory but face the same ordered, bulk persistence problem on disk. Skip lists (William Pugh, 1990s) solved in-memory ordered structure concurrency and simplicity, not the disk write pattern.

Log Structures: Close but Incomplete

Write-ahead logs (WAL) use pure sequential writes for crash recovery, but logs are write-only; a point query would require a full scan, disastrous for read-heavy scenarios.

The core question became: can we make writes sequential like a log while retaining index-like query efficiency?

The Real Breakthrough: The 1996 Paper

In 1996, Patrick O'Neil, Edward Cheng, Dieter Gawlick, and Elizabeth O'Neil published "The Log-Structured Merge-Tree (LSM-Tree)" in Acta Informatica. Their insight was simple yet disruptive: instead of organizing every write immediately into a final index structure, buffer writes, flush them sequentially to disk, then gradually merge the fragments into larger ordered files via background processes.

LSM Tree Tiered Structure

MemTable : New writes first enter an in-memory ordered structure (later implementations use skip lists or red-black trees).

SSTable (Sorted String Table) : When the MemTable reaches a size threshold, it is flushed sequentially to disk as an immutable ordered file.

Compaction : A background process continuously merges multiple SSTables into larger, more ordered files, discarding obsolete or overwritten data.

The elegance: all disk writes — whether MemTable flushes or SSTable merges — are sequential. Random writes are removed from the critical path; the trade-off is that reads may need to check multiple files, a cost mitigated by Bloom filters and block indexes.

The paper made little splash initially. Its widespread recognition came a decade later through Google's Bigtable (2006), LevelDB, and Amazon's Dynamo (2007). Google engineers independently arrived at the same design and validated it at massive scale.

Source Code Insight: A Get Operation's Choices

In LevelDB/RocksDB, a Get(key) follows a strict order:

Check the active MemTable (latest writes, not yet flushed).

Check the immutable MemTable (being flushed).

Scan disk SSTables from the newest level downward.

This order exists because LSM Tree allows the same key to exist in multiple places — updates are appended as new versions, not in-place overwrites. Therefore, the newest version is always in the most recent structure; once found, the search stops. This design trades a few extra comparisons on the read path for the complete elimination of random I/O on the write path — a classic asymmetric optimization suited for write-heavy, read-light workloads.

Design Philosophy

LSM Tree embodies several engineering principles later repeatedly validated:

Sequential I/O First : Convert expensive random operations into cheap sequential ones.

Immutability : SSTables are never modified after creation, simplifying concurrency control and making caching and replication inherently safe.

Deferred Merging / Lazy Compaction : Do not organize data perfectly on every write; push reorganization to the background, trading time for write throughput.

Space for Time : Allow multiple versions of a key to coexist temporarily, using extra storage to gain write performance.

Tiered Merging (External Merge Sort) : SSTable merging is essentially external merge sort reused inside a storage engine.

None of these ideas were brand new; LSM Tree's contribution was unifying them into a single, practical storage model.

Why It Ultimately Won

Two converging forces in the late 2000s propelled LSM Tree adoption:

Internet data exploded; write-intensive scenarios (logs, messaging, time-series, user behavior streams) became ubiquitous, and B-Tree-based relational databases faltered.

Google proved with Bigtable that LSM Tree could sustain massive continuous write pressure in production, and the open-source LevelDB provided a readable reference implementation.

Subsequent systems adopted the paradigm almost wholesale: Cassandra borrowed from Dynamo and Bigtable; HBase is an open-source Bigtable clone; RocksDB is Facebook's high-performance rewrite of LevelDB; InfluxDB and ClickHouse's MergeTree engines, despite differing details, share the core "sequential write first, background merge later" paradigm; even Kafka's log segments and log compaction follow the same lineage.

The reason is straightforward: it turned the physical constraint "disks hate random writes" into a first-class software design principle, not an afterthought patch.

Are There Better Alternatives Today?

Hardware has changed since 1996, prompting re-evaluation:

SSD Adoption narrows the random-vs-sequential write gap (though SSDs still prefer sequential writes due to erase blocks and write amplification). This has spurred new compaction strategies (Leveled, Tiered, Universal) to balance read amplification, write amplification, and space amplification for flash.

New Data Structures like the Bε-Tree (B-epsilon Tree) aim for a middle ground between B-Tree read performance and LSM write performance, used in TokuDB and BetrFS.

Computational Storage & NVMe allow offloading compaction to the storage device, reducing CPU and main memory involvement.

Rust, Go, and Async I/O (io_uring) improve implementation efficiency but not the architecture — LSM's core idea (sequential write + background merge + tiered query) remains the default answer for write-intensive systems because it addresses a deeper physical and engineering law: appending beats overwriting.

Real-World Applications

LSM Tree and its variants now underpin a large portion of modern infrastructure:

LevelDB / RocksDB : Google and Facebook products, used as embedded engines in countless systems (early Ethereum clients, TiKV's storage layer).

Cassandra, HBase : Classic distributed NoSQL databases.

InfluxDB : Time-series database, naturally write-heavy.

ClickHouse : MergeTree engine family explicitly honors this lineage.

Kafka : Log segmentation and compaction mechanics.

CockroachDB, TiDB : Distributed SQL databases using RocksDB as the LSM storage engine.

Their commonality: they operate in a world of massive write pressure where background reorganization latency is acceptable.

Computer progress has never been about who writes the cleverest code, but about who sees the era's hardware temperament most clearly and designs with it, not against it.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CompactionLSM TreeRocksDBB-TreeSSTableDatabase StorageBigtableWrite-Heavy Workloads
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.