Try
↑ ↓ move↵ openesc close

Curriculum · Module 07, Storage Engines

Lesson 2 · 7 topics · 33 min · Intermediate · 0/7 done

LSM trees and compaction

Turn random writes into sequential ones with a memtable and sorted files, then pay the bill in compaction. Leveled and tiered policies trade write, read and space cost.

What each topic covers

  • A B-tree writes pages in random places. An LSM tree turns writes into appends and pays for it later.
  • How a write becomes a sorted file, how a read finds a key, and how a merge removes old versions.
  • Write forty thousand keys, switch the compaction policy, and read the three amplification numbers.
  • Leveled compaction pays in writes, tiered compaction pays in reads and space, and overwrites decide how big the space bill gets.
  • A point read, a miss and a range scan each touch files differently, and the number of files is what you pay for.
  • Compaction is debt paid in the background. If ingest outruns the merge, files pile up and the store must slow the writer.
  • Three quick checks on the LSM write path, the cost of a miss and the choice of policy, with the sources behind the lesson.

Topics

  1. 1Random writes are the expensive kind3 min
  2. 2Memtable, SSTables and compaction5 min
  3. 3Run leveled and tiered on the same writes8 min
  4. 4What each policy costs you5 min
  5. 5Why reads cost more here4 min
  6. 6When compaction cannot keep up4 min
  7. 7Memtables, runs and amplification4 min

Practise this lesson

8 interview questions on lsm trees, with worked answers and sources.

Practise these

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms