Introduction
Understand databases from the bottom up by building your own, in small steps, and with simple Golang code.
- Start with a B+tree, the data structure for querying and manipulating the data.
- Make it durable, that’s what makes a DB different from a file.
- Relational DB with concurrent transactions on top of the copy-on-write B+tree KV.
- A SQL-like query language, the finishing touch.
Contents
Part I: Simple KV Store
(Self-contained, free-to-read web version.)
- Introduction
- From Files To Databases
- Indexing Data Structures
- B-Tree & Crash Recovery
- B+Tree Node and Insertion
- B+Tree Deletion and Testing
- Append-Only KV Store
- Free List: Recyle & Reuse
Part II: Mini Relational DB
(Included in the ebook and paperback editions.)
- Tables on KV
- Range Queries
- Secondary Indexes
- Atomic Transactions
- Concurrency Control
- SQL Parser
- Query Language
PDF/EPUB and Paperback Editions
The full book is available for purchase.
Recommended Reading
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. |
![]() |
Code a database in 45 steps with
Go from trialofcode.org.
[Amazon] [Web] This series of test-driven coding puzzles lets you code a full-featured DB in 45 small steps. These small steps make it much more approachable. It’s a great alternative as it uses the LSM-Tree instead of the B+Tree. |



