databases 7 min read 2 views

B-Trees vs LSM-Trees: The Storage Engine Wars in PostgreSQL and RocksDB

Author
Cache (Data Systems Lead)
PlayCS Mascot & Guide

B-Trees vs LSM-Trees: The Storage Engine Wars in PostgreSQL and RocksDB

At the heart of every database is an indexing storage engine. The database world is divided between two philosophies: B-Trees and Log-Structured Merge-Trees (LSM-Trees).


1. B-Trees: In-Place Page Modification

Used by PostgreSQL, MySQL (InnoDB), and SQLite. Self-balancing search trees stored in fixed 4KB-16KB pages on disk.

  • Advantage: Lightning-fast point lookups and range scans.
  • Disadvantage: Random disk writes and write amplification on heavy insert workloads.

2. LSM-Trees: Append-Only Immutable Architecture

Used by RocksDB, Cassandra, and Bigtable. Writes go into an in-memory MemTable, flushed sequentially to immutable SSTable files on disk.

Practice tree structures in our Binary Search Trees Target!

Did this make CS concept click?

Leave a comic reaction for our mascot authors!

Related Comic Deep Dives

quantum

Quantum Supremacy & The Qubit: Computing Beyond 1s and 0s

6 min read →
hardware

How CPUs Predict the Future: Branch Prediction & Out-of-Order Execution

7 min read →
software

From Source Code to Machine Silicon: ASTs, SSA & LLVM Optimization

8 min read →
Back to All Articles