LSM trees explained in plain terms means understanding how a database can accept writes at full speed without ever updating data in place. The central question is how a system can handle thousands of writes per second on slow disk, and the answer is to write sequentially, in a log, and sort the data out later, in the background.
An LSM tree, short for log-structured merge-tree, is a data structure that stores writes first in memory and then in a series of sorted files on disk. New data is appended to the newest file, and older files are periodically merged together, in a process called compaction, so that the data stays organised without ever being rewritten in place.
The idea is simple: sequential writes are fast and random writes are slow, so a database should turn every write into a sequential one, and pay the cost of sorting later, when nobody is waiting. This article explains what LSM trees are, how they work, and where they are used.
Key takeaways
- An LSM tree buffers writes in memory, then flushes them as sorted files.
- All writes are sequential, which makes them fast on disk and flash.
- Compaction merges older files and removes deleted or stale data.
- Reads may check several files, so they are slower than in a B-tree.
- They suit write-heavy workloads such as logs, metrics, and time series.
What LSM trees are
An LSM tree is organised in levels. The first level is an in-memory table, often called a memtable, which holds recent writes in sorted order. When the memtable fills up, it is flushed to disk as a single sorted file, called an SSTable, and a new empty memtable takes its place. The disk files are grouped into levels, with each level holding roughly ten times as much data as the one above it.
The structure was introduced by Patrick O’Neil and his colleagues in 1996, in a paper that showed how a log-structured design could outperform a traditional B-tree for write-heavy workloads. The design lay largely unused for a decade, until the rise of write-heavy web services and flash storage made its trade-offs attractive again.
Every write in an LSM tree is an insert, even a delete. Updating a key writes a new version of it, and deleting a key writes a special marker, called a tombstone, that says the key is gone. The old versions stay on disk until compaction removes them, which is why an LSM tree can be slower to reclaim space than a structure that updates in place. Our guide to SSDs explains the flash storage on which sequential writes are fast, and our guide to file systems explains the files in which the sorted tables live.
How LSM trees work
A write begins in the memtable. The client sends a key and a value, the database appends the change to a write-ahead log for durability, and then inserts it into the memtable, which keeps keys sorted in memory. The write returns as soon as both are done, which takes microseconds, because neither step involves seeking on disk.
When the memtable reaches its size limit, it is flushed to disk as an SSTable. The flush writes the sorted keys out in order, producing one immutable file that is never modified again. Immutability is a key property: because files never change, they can be read safely by many threads at once, and a crash cannot corrupt a file that was already finished.
A read must search several places. It checks the memtable first, then the newest SSTables, then older ones, stopping at the first version it finds. To avoid searching files that cannot contain the key, each file carries a Bloom filter, a small summary that can say a key is definitely absent, though it may occasionally claim a key is present when it is not. The filter keeps most reads to a single file lookup.
Compaction is what keeps the structure healthy. In the background, the database picks a few overlapping files, reads them, merges their sorted keys, discards versions that have been superseded and tombstones whose data is gone, and writes the result out as new files in the next level down. Compaction is the price of fast writes: it reads and rewrites data several times, which is called write amplification.
Deletes are handled by tombstones. When a key is deleted, a tombstone is written like any other value, and reads that find the tombstone treat the key as absent. The tombstone and the old versions it covers are only removed when compaction merges the level that holds them with the levels below, so a deleted key can linger on disk until compaction reaches it.

Comparing LSM trees with other storage structures
LSM trees are one of several ways to store indexed data on disk, and each was built with a different emphasis. A B-tree updates data in place and reads fast, while a hash index looks up single keys quickly but cannot scan in order, and each structure trades write speed for read speed in a different way.
The table below sets out the main contrasts between the leading approaches.
| Aspect | LSM tree | B-tree | Hash index |
|---|---|---|---|
| Write speed | Very fast, sequential | Slower, random updates | Fast, single lookup |
| Read speed | Slower, checks several files | Fast, one path down | Very fast, one hash |
| Range scans | Good, data is sorted | Good, data is sorted | Poor, no order |
| Space use | Higher, until compaction | Tight, updated in place | Tight |
| Best for | Write-heavy workloads | Mixed reads and writes | Exact key lookups |
The practical result is that an LSM tree is the right choice when writes dominate and reads can tolerate a little extra work, a B-tree suits balanced workloads, and a hash index fits systems that only ever look up single keys.
Where LSM trees are used
LevelDB and RocksDB are the best-known LSM tree engines. LevelDB, written at Google, popularised the design for embedded use, and RocksDB, its successor at Meta, powers the storage layer of many larger systems, including distributed databases and message queues that need fast, durable writes.
Apache Cassandra stores its data in LSM trees. Each node writes to a memtable and flushes SSTables, and compaction runs continuously in the background, which is what lets Cassandra absorb very high write rates across a cluster while keeping the data sorted for efficient reads.
Apache HBase, the database behind large Hadoop deployments, is built on LSM trees. Its regions hold memtables that flush to files on distributed storage, and its compaction strategies are tuned for the huge, write-heavy tables that HBase is used for, such as web crawls and event logs.
Time series databases use LSM trees for metrics and events. A system that records millions of measurements per second needs writes to be cheap above all else, and the sorted, time-ordered files of an LSM tree are a natural fit for data that is almost always written in time order and read back by time range.
Message queues and streaming systems use LSM trees to store their logs durably. A broker that must persist every message before acknowledging it needs the fastest possible write path, and the sequential, append-only writes of an LSM tree give it exactly that.
Strengths and limits
The greatest strength of an LSM tree is write speed. Every write is a sequential append, which is the fastest operation a disk or a flash drive can perform, and writes never wait for a seek or a page split, so the system can absorb bursts that would overwhelm a B-tree.
It is also a strength that LSM files are immutable. Immutability makes concurrency simple, since readers never see a file change under them, and it makes crash recovery simple too, since a finished file is either fully written or not present at all.
The limits are real, though. Reads are slower, because they may check several files, and write amplification means compaction can consume a large share of the disk’s bandwidth, especially under sustained write load. Space is also used less efficiently, since stale versions linger until compaction removes them.
LSM trees checklist
- Use LSM trees when writes dominate the workload.
- Size the memtable to balance write latency and flush frequency.
- Keep Bloom filters enabled to avoid useless file lookups.
- Monitor compaction; falling behind means reads and space suffer.
- Tune compaction for your pattern: tiered for writes, levelled for reads.
- Expect deleted data to linger until compaction reaches it.
- Put the write-ahead log on fast, reliable storage.
- Test read latency under heavy write load, not just at idle.
- Plan disk headroom for compaction, which needs free space to work.
Frequently asked questions
What is an LSM tree in simple terms?
It is a way of storing data that writes everything sequentially, first to memory and then to sorted files on disk, and merges those files together in the background, so that writes are fast and sorting happens later.
What is an SSTable?
It is a sorted string table, an immutable file on disk that holds a sorted run of keys and values flushed from the memtable. Once written, an SSTable never changes; it is only merged away by compaction.
What is compaction?
It is the background process that merges overlapping SSTables, discards superseded versions and tombstones, and writes the result into the next level. It keeps reads fast and reclaims space, at the cost of extra disk work.
What is write amplification?
It is the extra disk writing caused by compaction: a single logical write may be rewritten several times as its file is merged down through the levels. Write amplification is the main cost of the LSM design.
Why are LSM reads slower than B-tree reads?
Because a read may need to check the memtable and several SSTables before it finds the newest version of a key, while a B-tree read follows a single path down one tree. Bloom filters reduce the cost, but do not remove it.
When should I not use an LSM tree?
When reads dominate, when point lookups must be as fast as possible, or when disk space is tight and stale versions are a problem. In those cases a B-tree or a hash index is usually the better choice.
The bottom line
LSM trees explained in one line is this: write sequentially now, sort in the background, and let reads do a little extra work.
They are the structure that makes write-heavy databases fast, trading read speed and disk work for a write path that never has to wait.
This article is general information about how LSM trees work, not advice about choosing a storage engine for a particular system.







