> Books > Build Your Own Database From Scratch
⟵ 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 in small steps and simple Golang code.

A step-by-step walkthrough of a minimal persistent database implementation.

  1. Start with a B+tree, the data structure for querying and manipulating the data.
  2. Make it durable, that’s what makes a DB different from a file.
  3. Relational DB with concurrent transactions on top of the copy-on-write B+tree KV.
  4. A SQL-like query language, the finishing touch.


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

PDF/EPUB and Paperback Editions

The full book is available for purchase.

I have curated a list of books that will further your understanding.

Database Internals by Alex Petrov.
[Amazon] [Web]
Many database books are either very academic, or talk about topics from a high level, few books go down to the practical side and examine databases in detail. Alex’s brilliant book not only explores the details and different approaches to storage engines, but is also a great introduction to distributed systems.
Designing Data-Intensive Applications by Martin Kleppmann.
[Amazon] [Web]
This classic book is not just about databases, but covers a much broader range of topics, especially about distributed systems. It explains topics using real-world systems and is universally recommended for software developers.
The Go Programming Language by Brian W. Kernighan.
[Amazon] [Web]
While you can follow this project and code your own DB in any language you like. Golang is still a solid choice. Coding something from scratch often involves some low-level stuff and interacting with the OS, which is traditionally done in C/C++. Golang is incredible because of its balance between system and application programming. You can pick up Golang quickly with this book by Brian W. Kernighan, the same “K” who wrote the classic “K&R”.

( Report an Error | Ask a Question) @

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 ⟶