Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics/Indexing & Storage Engines
STORAGE, CACHING & SEARCH · SUBTOPIC

B-Trees vs. LSM-Trees

Why PostgreSQL uses B-Trees while Cassandra and RocksDB use LSM-Trees.

IntermediatePart of Indexing & Storage Engines
Practice in AI HLD
Subtopics in Indexing & Storage Engines (2)
OverviewB-Trees vs. LSMIndexes & Bloom Filters

In plain words

A B-Tree keeps an alphabetically sorted filing cabinet and inserts each new file into its exact drawer immediately. An LSM-Tree stacks new papers neatly in an inbox (super fast!) and sorts them into folders later at night.

Think of it like…

Sorting books onto shelves as they arrive (B-Tree) vs. piling returns on a cart and shelving them in batches (LSM-Tree).

Loading interactive diagram
Loading interactive exercise

Theory & how it works

Compaction spikes to watch for

In LSM-Trees, background compaction merges older SSTable files and clears deleted rows ("tombstones"). Under heavy write load, compaction can briefly compete for disk I/O and spike read latency (p99).

Key points & practical guide

Summary checklist

  • B-Trees = predictable fast reads, in-place page updates
  • LSM-Trees = sequential fast writes, background compaction
  • Both use WAL for crash durability

When to use it

  • B-Trees for general SQL/OLTP
  • LSM-Trees for telemetry, logs, messaging history, write-heavy NoSQL

Watch out for

  • Unbounded compaction lag on LSM engines when disk IOPS saturate

Quick check

Loading quiz
Parent topic
Indexing & Storage Engines
Next subtopic
Composite Indexes, WAL & Bloom Filters