A Log-Structured Merge-Tree (LSM Tree) is a write-optimized data structure used in storage engines for databases and key-value stores. It achieves high write throughput by batching updates in an in-memory memtable and sequentially flushing them to disk as sorted, immutable SSTables (Sorted String Tables). This design minimizes random disk I/O, making it ideal for workloads with frequent inserts and updates, such as in time-series data or agentic memory systems managing rapid state changes.
Glossary
Log-Structured Merge-Tree (LSM Tree)

What is Log-Structured Merge-Tree (LSM Tree)?
A Log-Structured Merge-Tree (LSM Tree) is a high-performance storage engine data structure that batches writes in a memory-resident component (memtable) before merging them into sorted, immutable files on disk.
Reads query multiple levels of SSTables, potentially requiring a merge of results. A background compaction process continuously merges and rewrites these files into larger, consolidated levels, applying tombstones for deletions and enforcing the chosen eviction policy for old data. This tiered, log-structured approach is fundamental to systems like Apache Cassandra, RocksDB, and Google LevelDB, providing the durable, high-ingestion backend for agentic memory persistence and update operations.
Key Components of an LSM Tree
An LSM Tree is a high-performance storage engine that optimizes write throughput by batching updates in memory before merging them into sorted, immutable files on disk. Its architecture is defined by several core components that work in concert.
Memtable
The memtable is a mutable, in-memory data structure (typically a balanced tree like a Red-Black Tree or a skip list) that serves as the primary write buffer. All incoming writes (inserts, updates, deletes) are first appended to a write-ahead log (WAL) for durability and then applied to the memtable. When the memtable reaches a configured size threshold, it becomes immutable and is flushed to disk as a Sorted String Table (SSTable). This design allows for extremely high write throughput, as writes are sequential appends to the WAL and in-memory updates.
Sorted String Table (SSTable)
An SSTable is an immutable, sorted file on disk that stores key-value pairs. It is the persistent representation of a flushed memtable. Key characteristics include:
- Sorted by Key: Enables efficient range queries and merging.
- Immutable: Once written, it is never modified in place.
- Indexed: Contains a sparse in-memory index (e.g., a Bloom filter and block offsets) for fast point lookups.
- Compressed: Often compressed to reduce storage footprint. SSTables are organized into levels (L0, L1, L2...), with each level having a size limit. Newer data resides in smaller, higher levels (like L0), and older data is gradually merged into larger, lower levels.
Compaction
Compaction is the background process that merges multiple SSTables from one level into a new, larger SSTable at the next level. It is the core mechanism for:
- Space Reclamation: Removing obsolete or deleted values (tombstones).
- Read Optimization: Reducing the number of files that must be checked for a read.
- Write Amplification Control: Managing the cost of rewriting data. Common compaction strategies include Leveled Compaction (strict size tiers, better read performance) and Size-Tiered Compaction (merging similarly sized files, better write performance). The choice involves a trade-off between write amplification and read amplification.
Write-Ahead Log (WAL)
The Write-Ahead Log (WAL) is a sequential, append-only log file on persistent storage. Every write operation is durably written to the WAL before being applied to the memtable. This provides crash consistency: if the system fails, the memtable can be reconstructed by replaying the WAL. Once a memtable is successfully flushed to an SSTable, its corresponding WAL segments can be safely deleted. The WAL is critical for the durability guarantee of the LSM Tree, ensuring no acknowledged writes are lost.
Bloom Filter
A Bloom filter is a probabilistic, memory-efficient data structure used to accelerate point reads. Each SSTable has an associated Bloom filter in memory. When checking for a key, the Bloom filter can definitively say "key is definitely not present" or "key is probably present" with a very low, configurable false-positive rate. This prevents expensive disk I/O for the vast majority of queries seeking non-existent keys. For example, a 1% false-positive rate means only 1 in 100 negative lookups will incur an unnecessary disk seek, dramatically improving read performance for workloads with many misses.
Manifest File
The manifest file is a persistent metadata log that tracks the schema of the LSM Tree. It records:
- The sequence of SSTable files.
- The level to which each SSTable belongs.
- Key range boundaries for each SSTable.
- Compaction history and status. This file is essential for recovery and consistency. When a database starts, it reads the manifest to reconstruct its in-memory view of the SSTable hierarchy. The manifest is updated atomically during major events like flushes and compactions to maintain a consistent view of the storage state.
How an LSM Tree Works: The Write and Compaction Cycle
A Log-Structured Merge-Tree (LSM Tree) is a high-performance storage engine data structure that optimizes write throughput by batching writes in memory before merging them into sorted, immutable files on disk. Its core operational cycle consists of two fundamental phases: the write path and the background compaction process.
The write path begins with incoming data being sequentially appended to an in-memory buffer called a memtable. This provides extremely fast write latency. Once the memtable reaches a size threshold, it is flushed to disk as a new, immutable Sorted String Table (SSTable) file. Concurrently, a new memtable is created to accept writes, ensuring continuous operation. This design transforms random disk writes into sequential ones, which is the primary source of the LSM tree's high write performance.
The compaction cycle is the background process that merges and reorganizes these immutable SSTable files. As more SSTables accumulate, reads become slower because a key might exist in multiple files. Compaction selects several SSTables, merges their sorted entries, discards obsolete or deleted values (marked by tombstones), and writes out new, consolidated SSTables. This process reduces the total number of files, improves read performance, and reclaims disk space. Major compaction strategies include size-tiered and leveled compaction, which balance write amplification and read efficiency.
LSM Tree vs. B-Tree: A Performance Trade-off Analysis
A technical comparison of two foundational data structures for high-performance storage engines, focusing on their core operational trade-offs for write-heavy, read-heavy, and mixed workloads.
| Architectural Feature / Metric | Log-Structured Merge-Tree (LSM Tree) | B-Tree (and variants like B+ Tree) |
|---|---|---|
Core Write Pattern | Append-only, batched writes to immutable sorted files (SSTables). | In-place updates within balanced tree nodes on disk. |
Core Read Pattern | Multi-level search across memtable and multiple SSTable files. | Traversal of a single, balanced tree structure from root to leaf. |
Write Amplification | High (4-10x typical). Caused by repeated compaction/merging of SSTables. | Low (theoretically ~1x). Each key update writes only its node and ancestors. |
Read Amplification | Potentially high. Requires checking multiple SSTable levels; optimized with Bloom filters. | Low and predictable. Bounded by tree height (O(log n)). |
Write Throughput | Extremely high for sequential inserts/updates. Ideal for write-heavy workloads (e.g., logging, time-series). | Lower, limited by random I/O for in-place updates. Can bottleneck on disk seeks. |
Read Latency (Point Query) | Good to excellent with Bloom filters. Can degrade without compaction or with many SSTable levels. | Excellent and consistent. Predictable latency from tree traversal. |
Range Query Performance | Good, but requires merging iterators from multiple SSTables. Sequential scan of SSTables is efficient. | Excellent. Leaf nodes are linked, enabling fast sequential traversal of sorted keys. |
Space Amplification | Can be high due to multiple copies of data during compaction and tombstones for deletes. | Low. Data is stored primarily in one location (leaf nodes). |
Background I/O | Heavy, periodic, and bursty due to compaction operations. Can impact foreground latency. | Minimal and integrated. Page splits/merges occur during foreground operations. |
Concurrency Control | Simpler. Writes go to single memtable; reads are lock-free from immutable SSTables. | More complex. Requires fine-grained locks (latches) on tree nodes for in-place updates. |
Optimization for SSDs | Excellent. Sequential writes and large block I/O align well with SSD characteristics. | Good, but random writes can cause write amplification on SSDs (wear leveling). |
Crash Recovery | Simple via replay of Write-Ahead Log (WAL) for memtable and SSTable manifest. | Complex, requiring careful WAL replay and potential tree structure repair. |
Primary Use Cases | Write-optimized databases (Cassandra, RocksDB, LevelDB), time-series, logging systems. | Read-optimized and general-purpose databases (MySQL InnoDB, PostgreSQL, traditional RDBMS). |
Frequently Asked Questions
A Log-Structured Merge-Tree (LSM Tree) is a write-optimized data structure fundamental to modern storage engines. These questions address its core mechanics, trade-offs, and role in agentic memory systems.
A Log-Structured Merge-Tree (LSM Tree) is a high-performance storage engine data structure that optimizes for high-throughput write operations by batching and sequentially writing data to disk. Its core mechanism involves two primary components: a memory-resident memtable and a hierarchy of sorted, immutable files on disk called SSTables (Sorted String Tables).
- Write Path: All incoming writes (inserts, updates, deletes) are first appended to a write-ahead log (WAL) for durability, then applied to the in-memory memtable, which is typically a balanced tree like a skip list.
- Flush: When the memtable reaches a size threshold, it is frozen, and its sorted contents are written to disk as a new SSTable at Level 0 (L0).
- Compaction: A background process called compaction merges these SSTables from one level to the next, combining data, discarding overwritten values, and deleting tombstoned entries. This creates larger, sorted SSTables at higher levels (L1, L2, etc.).
This design transforms random writes into sequential disk I/O, making it exceptionally fast for write-heavy workloads common in logging, time-series data, and agentic memory systems where state updates are frequent.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
These core concepts define the policies and mechanisms for managing data lifecycle within storage engines and agentic memory systems, directly complementing the LSM Tree's merge-based update strategy.
Write-Ahead Log (WAL)
A durability guarantee protocol where all data modifications are first written to a persistent, append-only log file before being applied to the main database structure. This ensures crash recovery by allowing the system to replay the log to reconstruct the latest committed state.
- Core Mechanism: Acts as a single source of truth for recent writes.
- Relation to LSM Trees: Often used in conjunction with an LSM Tree's memtable; writes are logged to the WAL before being inserted into the in-memory memtable, guaranteeing no data loss if the process crashes before a memtable is flushed to disk.
Cache Eviction Policy
A predetermined algorithm that determines which items to remove from a cache when it reaches its capacity limit. These policies are critical for optimizing the performance of in-memory components like an LSM Tree's memtable or a block cache.
- Common Algorithms: Least Recently Used (LRU), Least Frequently Used (LFU), and Time-To-Live (TTL).
- System Impact: The choice of policy directly affects cache hit rates, latency, and overall system throughput. In LSM Trees, the memtable acts as a write cache with its own implicit eviction policy: flush to disk when full.
Write-Back Cache
A storage optimization technique where data modifications are written only to a fast cache (e.g., memory) initially. Updates to the slower, persistent backing store are deferred until the cached data is evicted or explicitly flushed.
- Performance vs. Durability Trade-off: Maximizes write throughput but introduces a window where data is volatile. A crash before the flush results in data loss unless paired with a WAL.
- LSM Tree Parallel: The LSM Tree's memtable is a canonical write-back cache for disk. All writes first go to the memtable; the merge and flush to Sorted String Tables (SSTables) is the deferred write-back operation.
Bloom Filter
A probabilistic, memory-efficient data structure used to test whether an element is a member of a set. It returns either 'possibly in set' or 'definitely not in set,' with a tunable false-positive rate.
- Key Use Case in LSM Trees: Placed in front of on-disk SSTable files. Before performing a potentially expensive disk read to check for a key, the system queries the Bloom filter. If it returns 'definitely not present,' the read is avoided entirely, dramatically improving read performance for non-existent keys.
- Space Efficiency: A Bloom filter's small size (often a few MB per GB of data) makes this optimization highly cost-effective.
Multi-Version Concurrency Control (MVCC)
A database isolation technique that allows multiple transactions to read and write concurrently by maintaining multiple timestamped versions of data items. Readers see a consistent snapshot from a specific point in time, preventing conflicts with concurrent writers.
- Consistency Model: Enables snapshot isolation and repeatable reads.
- Relation to LSM Updates: LSM Trees naturally support MVCC-like semantics. When a key is updated, the new value is written as a new entry. Older values in immutable SSTables remain until garbage-collected during a merge. This allows for historical queries and consistent reads during compaction.
Garbage Collection (Compaction)
In the context of LSM Trees, garbage collection is the process of merging and rewriting SSTable files to reclaim space occupied by obsolete or deleted data (tombstones). This is performed by the compaction process.
- Mechanism: As SSTables are merged, only the most recent version of a key is kept in the new output file. Deleted keys marked with tombstones are discarded once they are known to have propagated through all relevant levels.
- Critical Function: Prevents unbounded disk space growth and read amplification by consolidating data and removing redundancy. Different compaction strategies (e.g., Leveled, Tiered) trade off write and read amplification.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us