Module 2 · Indexes
Episode 15 LSM Trees
▶ This video is coming to YouTube soon.
Why do RocksDB, Cassandra and LevelDB never update a page in place? This episode animates an LSM tree with a 4-entry memtable: the WAL, flushes to immutable SSTables, reads from newest to oldest and deletes as tombstones, then finds the same trick inside Postgres's GIN index: a pending list of 1,000 rows merged in bulk.
Chapters
- 0:00Intro
- 0:13Never write in place
- 0:36In place, every write is a random write
- 1:18Writes: log it, sort it in memory, flush it
- 2:44Reads: memtable first, then newest to oldest
- 3:46Deletes are writes: tombstones
- 4:37The LSM tree in six rules
- 5:21The code: put, delete, get
- 5:51The code: flush
- 6:19Proof: the same trick inside Postgres
- 7:47Same idea, not an LSM tree
- 8:14Trade-offs
- 8:53Recap
- 9:18Next: Compaction