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 07 · From Scratch · Database · with code: Go · about 17 min to read

Play it as a journeyTutor comes with a plan

Build Your Own Database, From Scratch

The Map
The Map · Open board

The whole build, laid out in the order its own walls forced it.

Boards

Code: teaching/code/from-scratch/database/: one Go module, go run ./NN-stage. Real files, a real B-tree (verified: 1000 keys, height 6, in-order sorted), real crash recovery, real MVCC snapshots, a tiny SQL planner.

Before you start. This series builds a small copy of a database: a program that keeps rows of data on disk, finds any one of them in an instant, survives the machine dying mid-write, and lets more than one program read and write at once without corrupting each other’s work. It’s the fourth build in the From Scratch track. If you built the small cache or the small message log earlier in it, you already know the shape, start from the plainest file that could work, and add exactly one new mechanism each time it hits a wall it can’t get past on its own.


Lesson 45 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

  • Spring 2000: a valve, a crashed dialog box, and no one to blame
  • A file you only add to
  • The fix: an index
  • What a disk actually moves
  • A tree built to live on pages
  • The fix: write it down before you do it
  • The fix: never erase, just add another version
  • The last board: teaching the file to answer a question
  • The nine problems, in order
  • One INSERT, end to end
  • What you can run today
  • The nine lessons
  • Go, as you go (new-to-Go markers)

Terms it explains: real B-tree, index, page, B-tree, write-ahead log, snapshot, transaction, log (WAL), transactions, no order, pages, pager, and, fsync before touching data, version, vacuum, planner, CRASH, sequential and crash-safe, scan the whole history, sorted, buffer pool, Atomicity, Durability, versioned copies, declarative, indexed, unindexed.

Review From Scratch