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
System Design topics
Lesson 9/ 31
Storage, Caching & Search

Indexing & Storage Engines

Understand B-Trees, LSM-Trees, WALs, and Bloom filters to explain read vs. write speed.

IntermediateB-Tree · LSM-Tree · WAL3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
B-Trees vs. LSM-Trees

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

Intermediate
Composite Indexes, WAL & Bloom Filters

Leftmost prefix rule, covering indexes, and skipping disk reads with Bloom filters.

Intermediate

In plain words

An index is like the index at the back of a book: instead of reading every page to find a word, you jump straight to it. Storage engines decide how data is physically written to disk.

Think of it like…

A B-Tree is an alphabetical binder where you erase and rewrite pages in place; an LSM-Tree is a notebook where you only append new notes at the end and merge notebooks overnight.

Where you’ve seen it

Searching 100M users by email without an index scans every row. With an index on email, the database finds the match in a few milliseconds.

Words you’ll hear

Index
An extra structure that makes lookups on a column fast.
B-tree
A sorted tree index; great for reads and range queries.
LSM tree
A write-optimized engine that buffers writes and merges them later.
Full table scan
Reading every row because no useful index exists. Slow at scale.

Visual diagram

Loading interactive diagram
Loading interactive exercise

Theory & deep dive

Why indexes make queries 1,000× faster (and cost writes)

Without an index, finding WHERE email = "a@b.com" forces a full table scan across millions of rows. An index keeps a sorted lookup map pointing straight to the matching row in O(log N) - roughly 3–4 steps for 100 million rows.

The catch: every INSERT, UPDATE, or DELETE must also update every index on that table. Over-indexing slows down writes and eats extra RAM/disk.

Key takeaway: Indexes turbocharge reads at the cost of slower writes and extra storage.

WAL (Write-Ahead Log) and Bloom Filters

Both B-Trees and LSM-Trees write changes sequentially to an append-only Write-Ahead Log (WAL) before saying "committed." If power fails mid-operation, the database replays the WAL on reboot so nothing is lost.

LSM-Trees also use Bloom filters - tiny bit arrays in RAM that tell you instantly "this key is DEFINITELY not in this SSTable file" - skipping pointless disk reads.

How it works, step by step

Step 1 of 4
Durability Layer

1. Append durability first via the Write-Ahead Log (WAL)

Before mutating complex tree structures, every write appends sequentially to an on-disk WAL so crashes can replay committed state.

Sequential append + fsync = crash-safe durability
Key numbers at this step
Write Pattern
Sequential append
Crash Recovery
WAL replay

When to use it & trade-offs

What it is

Storage engines organize bytes on disk. B-Trees update sorted pages in place for fast reads, while LSM-Trees append sequentially to memory/SSTables for fast writes.

Why it matters: Knowing why B-Trees favor reads and LSM-Trees favor heavy writes lets you tune indexes, avoid write amplification, and pick the right DB engine.

When to reach for it

  • Adding composite indexes aligned with WHERE col1 = ? AND col2 > ? (equality before range)
  • Choosing LSM-backed engines for write-heavy telemetry, chat history, or ingestion
  • Using Bloom filters in caches/DBs to reject non-existent keys cheaply

When to avoid or be careful

  • Creating an index on every column of a write-heavy table
  • Using UUIDv4 as a primary key in a clustered B-Tree (causes severe page splitting and cache thrashing - use ULID/UUIDv7)

B-Tree vs. LSM-Tree Engines

B-Tree (InnoDB, PostgreSQL)
Best for: Read-heavy OLTP, point lookups, range queries, predictable tail latency

Strengths: Every key exists in one place; fast reads with zero compaction stalls.

Watch out: Random 4–16 KB page writes and write amplification on heavy random inserts.

LSM-Tree (RocksDB, Cassandra, Scylla)
Best for: Write-heavy ingestion, logs, time-series, high compression

Strengths: Sequential disk writes give huge write throughput and better compression.

Watch out: Reads may check multiple SSTables (mitigated by Bloom filters); compaction spikes.

Composite & Covering Indexes
Best for: High-QPS SQL queries filtering on multiple columns

Strengths: Leftmost prefix ordering + covering columns let queries finish in index-only scans.

Watch out: Every extra index slows down INSERT/UPDATE/DELETE and consumes RAM/disk.

Interview signals & numbers to know

When this topic comes up

  • slow SQL query
  • write amplification
  • SSTable
  • random UUID primary key
  • Bloom filter

Benchmarks & rules of thumb

4-level B-Tree capacity -
Up to ~10⁹ keys
Bloom filter size (1% FP) -
~10 bits per key
Sequential vs random HDD/SSD -
5–50× faster
Postgres page size -
8 KB

Common mistakes & follow-ups

Common interview mistakes

  • Indexing low-cardinality booleans or putting range columns first in a composite index
  • Using random UUIDv4 as a clustered primary key in MySQL/InnoDB instead of time-ordered UUIDv7/Snowflake
  • Assuming Bloom filters can delete keys easily (standard Bloom filters only support insert & lookup)

Likely interviewer follow-ups

  • Why do random UUIDv4 primary keys degrade B-Tree write performance at scale?
  • How do Bloom filters prevent cache penetration and speed up LSM-Tree reads?
  • Explain write amplification vs. read amplification between B-Trees and LSM-Trees.
Interview tip: Remember the composite index rule: put equality columns first, sort/range columns after, and consider time-ordered IDs (UUIDv7/Snowflake) for B-Tree locality.

Knowledge check

Loading quiz

Put it into practice

Design full architectures with AI feedback

Apply Indexing & Storage Engines inside real High-Level Design prompts or review Q&A flashcards.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Database Design (SQL vs. NoSQL)
Next topic
Replication & Partitioning (Sharding)