Introduction

Understand databases from the bottom up by building your own, in small steps, and with simple Golang code.

  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.

Contents

Part I: Simple KV Store

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

  1. Introduction
  2. From Files To Databases
  3. Indexing Data Structures
  4. B-Tree & Crash Recovery
  5. B+Tree Node and Insertion
  6. B+Tree Deletion and Testing
  7. Append-Only KV Store
  8. Free List: Recyle & Reuse

Part II: Mini Relational DB

(Included in the ebook and paperback editions.)

  1. Tables on KV
  2. Range Queries
  3. Secondary Indexes
  4. Atomic Transactions
  5. Concurrency Control
  6. SQL Parser
  7. Query Language

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”.