Skip to content
Course contents

Storage and Retrieval

What a database actually does with your bytes — logs, indexes, B-trees, LSM-trees — and why the answer depends on whether you are writing or reading.

5 lessons2 labs2 hr 29 min

What you will be able to do

  • Build the simplest database that works, and explain exactly where it falls over
  • Explain what an index costs on write in exchange for what it saves on read
  • Describe how an LSM-tree turns random writes into sequential ones, and what compaction is paying for
  • Compare a B-tree and an LSM-tree on write amplification, read amplification and space, and pick one for a stated workload
  • Say why an analytics query wants its data stored by column and a transaction wants it by row

This is the module where the database stops being a black box.

You will start by writing a database in two lines of shell, watch it work, and watch it become unusable at exactly the point you would predict. Fixing it — without ever giving up the thing that made it fast — walks you through hash indexes, sorted string tables, log-structured merge trees, and B-trees, in the order the industry discovered them and for the reasons it discovered them.

By the end you will be able to answer the question that decides which database to reach for: does this workload write more than it reads, and does it read one row or ten million? That question has a different answer for the checkout page than for the dashboard your CFO opens on Monday, which is why one company usually runs both kinds of engine.

This module has the most labs. That is on purpose — a storage engine is a thing you understand by building a small wrong one first.

Read alongsideChapter 3 of Designing Data-Intensive Applications.

In this module7

Start module 3