TRT
Sign in

Expert · Module 27 · Lesson 5 of 5

LSM trees in RocksDB

How RocksDB answers a point lookup through a skip-list memtable, overlapping L0 files and one merged L1 run, counting probes with bloom filters off, and what compaction bills in write amplification.

Pro — members onlyAbout 14 minutes

By the end you can

  • Trace a point lookup through the memtable, L0 and L1, counting probes with and without compaction
  • Explain how a flush creates an L0 file, how the compaction trigger fires, and what compaction merges
  • Trade off write amplification, read amplification and space when tuning a leveled LSM tree

Builds on B-trees and pages, Amortized analysis.

01 · A question first

RocksDB cannot rewrite a disk index on every write; a random update on flash is the most expensive thing it could do. So it buffers writes in a sorted in-memory table, flushes them as files, and keeps rewriting files until each level holds one sorted run. The trace below counts probes with RocksDB's default table options — filter_policy left at nullptr, so no bloom filters — and every default cited comes from RocksDB's own headers.

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Why a store rewrites its data instead of updating it
  • The trace above: one probe at a time
  • Where L0 comes from
  • Compaction: twelve entries into nine
  • What a filter would have bought
  • The bill, and where it shows up
  • Pseudocode & Multi-Language Implementations (C++, Java, Python)
  • Complexity Derivation, Edge Cases & Common Mistakes

03 · Practice

Something wrong with this lesson? Report a problem