Skip to content
Computing Rich #lsm#compaction#rocksdb

LSM Tree: Memtable, SSTables, Compaction

Writes go to memory, flush to immutable files, compact in background. Append-only beats random writes.

A free, animated lsm tree: memtable, sstables, compaction you can read here or embed on any website, from Scrollchart.

LSM Tree: Memtable, SSTables, Compaction

LSM Tree: Memtable, SSTables & CompactionAppend-only writes in RAM, flush to disk, background compaction merges levels (10x size per level)Memtablein RAM, sorted (Red-Black tree)~64 MB defaultWrites (in-order)flush (fsync)Level 0 (overlapping key ranges)SSTable L0-1~2 MBSSTable L0-2~2 MBSSTable L0-3~2 MBSSTable L0-4~2 MB4 files trigger compactioncompact (sort + merge)Level 1 (non-overlapping, 10 MB)SSTable L1-1..Nsorted, disjoint key rangesLevel 2 (100 MB)SSTable L2-1..N10x L1 capacity, disjointLevel 3 (1 GB)SSTable L3-1..N (bulk of data)tombstones finally purged hereWrite pathWAL append (durability)Memtable insert (O(log n))Flush to L0 SSTableBackground compactionRead pathCheck memtable firstCheck L0 (all files, overlap)Binary search L1, L2, L3...Bloom filter prunes missesDelete = tombstone recordPurged only when compacted past all levelsWrite amplification: ~10-30x across all levels. Space amplification: ~1.1x (vs B-tree 2x). Read amplification: O(levels).

Writes land in the memtable (sorted in RAM). On full, the memtable flushes to a level-0 SSTable. Background compaction merges level-0 into level-1, level-1 into level-2 with size multiplier. Tombstones for deletes propagate down. Leveled vs tiered compaction strategies compared.

Good for

  • RocksDB tuning articles
  • KV-store design content
  • Write-heavy workload analyses

Source & accuracy

This lsm tree: memtable, sstables, compaction is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

From memtable through SSTables to compacted stores

An LSM tree begins with an in-memory buffer (memtable) receiving all writes. When the memtable fills, it is flushed as an immutable sorted file (SSTable) on disk. New writes go to a fresh memtable. Multiple SSTables accumulate; reading requires checking each to find the latest version of a key. Compaction merges overlapping SSTables into fewer, larger files, improving read performance and freeing disk space.

This append-only design avoids random writes: memtable writes are sequential RAM, SSTable writes are sequential disk I/O. Compaction runs in the background, not blocking active reads or writes. The result is throughput suitable for write-heavy workloads, at the cost of read latency (checking multiple files) and background CPU/disk usage.

Compaction levels and tuning strategies

Level-based compaction groups SSTables by level. Level 0 contains fresh flushes; Level 1 is larger, Level 2 even larger. Compaction merges adjacent levels, maintaining size invariants. This keeps the number of levels (and thus read amplification) logarithmic in total data size. Tiered compaction instead groups SSTables into equal-sized tiers, trading slower reads for fewer compactions.

Compaction tuning is critical: too-frequent compaction wastes CPU and I/O; too-infrequent leaves excessive SSTables and slows reads. Parameters like level multiplier, compaction ratio, and target file sizes control the tradeoff. Write-heavy systems tune for low write-amplification; read-heavy systems prioritize read performance, accepting more compaction overhead.

Embed this diagram

Add this animated lsm tree: memtable, sstables, compaction to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated lsm tree: memtable, sstables, compaction for any website.
Who uses it
Developer blogs, DevOps / SRE sites.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="lsm-tree-compaction" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "LSM Tree: Memtable, SSTables, Compaction" for my website?
Scrollchart provides "LSM Tree: Memtable, SSTables, Compaction" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a lsm tree: memtable, sstables, compaction in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.