Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 08 · From Scratch · LSM Tree · with code: Go · about 9 min to read

Play it as a journeyTutor comes with a plan

Build Your Own LSM Tree

Storage Engines
Storage Engines · Open board

The Data Systems board on the two honest ways to put bytes on a disk and find them again. The B-tree is one of them. This build is the other. Head of the LSM series, after the Database build (Build Your Own Database, From Scratch).

Before you start. This series builds a small copy of a storage engine: the part of a database that stores keys and values on disk and finds them again. The Database build made one kind, a B-tree that edits pages in place. This one makes the other kind, which never edits anything: it only appends, sorts in batches, and merges in the background. You need Storage Engines for the two-engine picture and Write-Ahead Log for why a write must reach a log before anything else. Storage Extras: richer indexes, warehouse schemas, column tricks covers Bloom filters and compaction in prose. This build writes them. The lab lsm-vs-btree puts a dial on the trade between the two engines.

Lesson 55 of 117 in From Scratch

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 2006: a sorted buffer, a log, and a pile of immutable files
  • The bet an LSM tree makes
  • Seven stages, one module
  • The lessons
  • Run all seven
  • What this build leaves out

Terms it explains: memtable, SSTable, compaction, tombstone, Bloom filter, index, LSM, WAL.

Lab

Write-heavy wants an LSM, read-heavy wants a B-tree. Where exactly is the flip?

Drag Share of the workload that is reads across its whole range and watch the winner under Who finishes first flip.

Open LSM vs B-tree

Related papers

Review From Scratch