Advanced Topic 48 of 51 Databases
LSM Trees
Write-optimized structures merging sorted runs.
How it works
A log-structured merge tree optimizes write throughput by buffering writes in an in-memory sorted table, the memtable, and an append-only write-ahead log. When the memtable fills, it is flushed to disk as an immutable sorted file; background compaction merges files into larger sorted runs across levels. Reads check the memtable and then files from newest to oldest, using Bloom filters and indexes to skip files.
Where it is used
RocksDB, LevelDB, Cassandra, HBase, ScyllaDB and InfluxDB use LSM trees, which suit write-heavy workloads and make good use of sequential disk and SSD writes.
Common pitfall
Reads can be slower than in B-trees because several files may be checked, and compaction causes write amplification and background I/O spikes. Deletes use tombstones that linger until compaction. Tune compaction strategy, bloom filters and memory sizes for your workload, and monitor space and read amplification.
Where it fits in the course
LSM Trees is topic 48 of 51 in Databases, rated Advanced. It follows OLTP vs OLAP. The next topic is NewSQL and Distributed SQL.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
- Explore the Binary Search Tree visualizer: Insert keys and run traversals.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is LSM Trees?
Where do people use LSM Trees?
What is the most common mistake with LSM Trees?
What should I learn before this topic?
How can I practice it?
Is LSM Trees hard to learn?
How long does it take to learn LSM Trees?
Which topics are related to LSM Trees?
What should I study after LSM Trees?
Related topics
- OLTP vs OLAP (Databases)
- NewSQL and Distributed SQL (Databases)
- Data Warehousing (Databases)
- Time-Series Databases (Databases)
- Decision Trees (AI & Machine Learning)
- Trees in Graph Theory (Theory & Discrete Math)
- Trees (Data Structures)