Skip to content
Computing Rich #btree#lsm#storage-engine

B-Tree vs LSM Tree

B-trees: in-place updates, fast reads. LSM: append-only writes, compaction in background.

A free, animated b-tree vs lsm tree you can read here or embed on any website, from Scrollchart.

B-Tree vs LSM Tree

B-TreePostgreSQL, InnoDB, SQLiteLSM TreeRocksDB, Cassandra, LevelDB

A B-tree (Postgres/InnoDB style) with in-place page writes. An LSM tree (RocksDB/LevelDB style) with memtable, immutable SSTables, and tiered compaction. Write amplification, read amplification, space amplification compared as bars under each. Workload band overlays showing where each shines.

Good for

  • Database internals articles
  • Choosing storage engines
  • KV-store architecture explainers

Source & accuracy

This b-tree vs lsm tree 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.

In-place updates versus append-only writes

A B-tree organizes data in sorted blocks and modifies them in place. Inserting a new key finds the appropriate leaf block, inserts the key, and if the block overflows, splits it. Reads are fast because data is organized by value: a range query scans contiguous sorted blocks. Updates are also in-place and immediate.

An LSM (Log-Structured Merge) tree is append-only: writes go to an in-memory buffer (memtable), and when full, are flushed as an immutable sorted file (SSTable). Read amplification occurs because a key might exist in multiple SSTables. Compaction merges overlapping SSTables in the background, eventually consolidating old data. LSM trees sacrifice read performance for write throughput and reduced write amplification.

Tradeoffs and database system choices

B-trees win when reads are frequent and latency-sensitive. Random writes in B-trees cause seeks on disk, but batch-ordered queries are fast. LSM trees excel under write-heavy workloads with sequential I/O: writes to the memtable and sequential SSTables are much faster than random B-tree seeks. Compaction can be deferred, amortizing its cost.

RocksDB and LevelDB use LSM structures and dominate write-heavy applications. MySQL and PostgreSQL use B-trees for their maturity and simple read semantics. Modern systems (CockroachDB, Cassandra) use LSM variants. The choice depends on workload: OLTP favors B-trees, OLAP and streaming favor LSM. In practice, hybrid approaches tune write-amplification, read-amplification, and space-amplification tradeoffs.

Embed this diagram

Add this animated b-tree vs lsm tree 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 b-tree vs lsm tree for any website.
Who uses it
Developer blogs, DevOps / SRE sites, CS educators.
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="btree-vs-lsm" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "B-Tree vs LSM Tree" for my website?
Scrollchart provides "B-Tree vs LSM Tree" 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 b-tree vs lsm tree 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.