Build Your Own Database From Scratch EBook·Paperback
⟵ prev Contents next ⟶

🔥 My other Book: Build Your Own Redis

Build Your Own Database From Scratch

Persistence, Indexing, Concurrency

James Smith


Databases are not black boxes. Understand them by building your own from scratch!

This book contains a walk-through of a minimal persistent database implementation. The implementation is incremental. We start with a B-Tree, then add a new concept with each chapter, and eventually go from a simple KV to a mini relational DB.

Although the book is short and the implementation is minimal, it covers three important topics:

  1. Persistence. How not to lose or corrupt your data. Recovering from a crash.
  2. Indexing. Efficiently querying and manipulating your data. (B-tree).
  3. Concurrency. How to handle multiple (large number of) clients. And transactions.

Sample code written in Golang.


Part I: Simple KV Store

(Self-contained, free-to-read web version.)

  1. Introduction
  2. Files vs Databases
  3. Indexing
  4. B-Tree: The Ideas
  5. B-Tree: The Practice (Part I)
  6. B-Tree: The Practice (Part II)
  7. Persist to Disk
  8. Free List: Reusing Pages

Part II: Mini Relational DB

(Included in the ebook and paperback editions.)

  1. Rows and Columns
  2. Range Query
  3. Secondary Index
  4. Atomic Transactions
  5. Concurrent Readers and Writers
  6. Query Language: Parser
  7. Query Language: Execution

The book is available for purchase.

See also: offers “Build Your Own X” courses in many programming languages.
Including Redis, Git, SQLite, Docker, and more.
Check it out

⟵ prev Contents next ⟶