# Database Tutorials in Build Your Own X: 14 Hands-On Projects from KV Stores to SQL Engines

> Explore 14 hands-on database tutorials in Build Your Own X. Learn to build KV stores, SQL engines, and more in C, Go, Python, Rust, and other languages.

- Repository: [CodeCrafters/build-your-own-x](https://github.com/codecrafters-io/build-your-own-x)
- Tags: tutorial
- Published: 2026-02-23

---

**The Build Your Own X repository hosts 14 curated database tutorials spanning key-value stores, B-Tree-based SQL engines, graph databases, and Redis-like servers across C, Go, Python, Rust, and five other languages.**

The codecrafters-io/build-your-own-x repository is a curated collection of step-by-step tutorials for implementing technologies from scratch. For developers seeking to understand database internals, the repository's Database section provides database tutorials that cover everything from low-level disk storage to high-level query parsing.

## Complete List of Database Tutorials

The database tutorials are located in the [`README.md`](https://github.com/codecrafters-io/build-your-own-x/blob/main/README.md) file under the heading `#### Build your own \`Database\`` (approximately lines 3939–3954). The section indexes 14 external tutorials organized by programming language:

### C and C++

- **C**: *Let's Build a Simple Database* teaches you to build a basic disk-backed storage engine with a minimal query language ([cstack.github.io/db_tutorial/](https://cstack.github.io/db_tutorial/)).
- **C++**: *Build Your Own Redis from Scratch* guides you through creating an in-memory key-value store with networking, persistence, and pub/sub capabilities ([build-your-own.org/redis](https://build-your-own.org/redis)).

### C# and Clojure

- **C#**: *Build Your Own Database* demonstrates how to construct a simple relational engine with a custom query parser ([codeproject.com](https://www.codeproject.com/Articles/1029838/Build-Your-Own-Database)).
- **Clojure**: *An Archaeology-Inspired Database* focuses on persistent immutable data structures for functional database design ([aosabook.org](http://aosabook.org/en/500L/an-archaeology-inspired-database.html)).

### Crystal and Go

- **Crystal**: *Why you should build your own NoSQL Database* builds a lightweight NoSQL store using Crystal ([medium.com](https://medium.com/@marceloboeira/why-you-should-build-your-own-nosql-database-9bbba42039f5)).

- **Go**: Three distinct tutorials are available:
  1. *Build Your Own Database from Scratch: From B+Tree To SQL in 3000 Lines* creates a full-stack B+Tree storage engine with SQL parser and query executor ([build-your-own.org/database/](https://build-your-own.org/database/)).
  2. *Code a database in 45 steps (TDD puzzles)* uses test-driven development to construct a tiny DB with Go's `testing` package ([trialofcode.org/database/](https://trialofcode.org/database/)).
  3. *Build Your Own Redis from Scratch* implements the networking layer, RESP protocol, and persistence for a Redis clone ([www.build-redis-from-scratch.dev/](https://www.build-redis-from-scratch.dev/)).

### JavaScript and Python

- **JavaScript**: *Dagoba: an in-memory graph database* provides a graph-oriented API for nodes and edges with query chaining ([aosabook.org](http://aosabook.org/en/500L/dagoba-an-in-memory-graph-database.html)).

- **Python**: Two tutorials are featured:
  1. *DBDB: Dog Bed Database* implements a mini relational DB with a tiny SQL-like language ([aosabook.org](http://aosabook.org/en/500L/dbdb-dog-bed-database.html)).
  2. *Write your own miniature Redis with Python* creates a simple key-value store exposing the Redis protocol ([charlesleifer.com](http://charlesleifer.com/blog/building-a-simple-redis-server-with-python/)).

### Ruby and Rust

- **Ruby**: *Build your own fast, persistent KV store in Ruby* constructs a persistent hash table on disk using Ruby's Marshal format ([dineshgowda.com](https://dineshgowda.com/posts/build-your-own-persistent-kv-store/)).
- **Rust**: The *Build your own Redis client and server* tutorial series uses async Tokio to implement RESP protocol handling and client libraries ([tokio.rs](https://tokio.rs/tokio/tutorial/setup)).

## Common Architecture Patterns

All database tutorials in the repository share a consistent high-level architecture comprising five core components:

1. **Storage Layer** — Implements either in-memory structures (hash maps, B-Trees) or on-disk file formats for data retention.
2. **Query / Command Parser** — Processes domain-specific languages or protocols such as SQL, RESP, or custom mini-languages.
3. **Execution Engine** — Translates parsed commands into storage layer operations including reads, writes, and range scans.
4. **Networking Interface** — For server-style tutorials, this component listens on sockets, decodes protocols, and manages client connections.
5. **Persistence / Durability** — Guarantees data survives restarts through write-ahead logs, snapshotting, or file appends.

Understanding these components clarifies why specific tutorials emphasize different aspects—the C tutorial focuses on low-level file I/O, while the Go B+Tree tutorial covers complete SQL engine implementation.

## Code Implementation Examples

### Minimal Key-Value Store in Python

This example illustrates the core storage pattern used in the Python Redis-style tutorials:

```python
class MiniKV:
    def __init__(self):
        self.store = {}

    def set(self, key: str, value: str) -> str:
        self.store[key] = value
        return "OK"

    def get(self, key: str) -> str:
        return self.store.get(key, "(nil)")

# Usage

db = MiniKV()
print(db.set("name", "Codecrafters"))   # → OK

print(db.get("name"))                  # → Codecrafters

```

The linked tutorials expand this pattern with TCP listeners and RESP protocol handling.

### B+Tree Node Structure in Go

The following snippet from the *Build Your Own Database (B+Tree → SQL)* tutorial demonstrates the low-level data structure powering the storage layer:

```go
type BTreeNode struct {
    keys     []int           // sorted keys
    children []*BTreeNode    // nil for leaf nodes
    leaf     bool
}

// Insert a key into a leaf node (splitting handled by the caller)
func (n *BTreeNode) insertNonFull(k int) {
    i := len(n.keys) - 1
    if n.leaf {
        n.keys = append(n.keys, 0)               // grow slice
        for i >= 0 && k < n.keys[i] {
            n.keys[i+1] = n.keys[i]
            i--
        }
        n.keys[i+1] = k
    } else {
        // find child to descend into
        for i >= 0 && k < n.keys[i] {
            i--
        }
        i++
        if len(n.children[i].keys) == maxKeys {
            n.splitChild(i)
            if k > n.keys[i] {
                i++
            }
        }
        n.children[i].insertNonFull(k)
    }
}

```

This B+Tree implementation later supports a full SQL parser and query executor.

## Locating the Database Tutorials in the Repository

The Build Your Own X repository functions as an index rather than hosting source code directly. To find the database tutorials:

- **File Location**: [`README.md`](https://github.com/codecrafters-io/build-your-own-x/blob/main/README.md) in the repository root
- **Section Header**: Search for `#### Build your own \`Database\``

- **Line Range**: Approximately lines 3939–3954 in the README

Each entry in this section links to external tutorials that provide complete source code and step-by-step instructions.

## Summary

- The codecrafters-io/build-your-own-x repository indexes **14 database tutorials** across 9 programming languages.
- Tutorial types range from **in-memory key-value stores** to **B+Tree-backed SQL engines** and **graph databases**.
- All tutorials follow a common architecture: **storage layer**, **parser**, **execution engine**, **networking interface**, and **persistence mechanism**.
- The tutorials are listed in [`README.md`](https://github.com/codecrafters-io/build-your-own-x/blob/main/README.md) under the Database section (lines ~3939–3954).
- Code examples demonstrate core concepts including **hash map storage** (Python) and **B+Tree node management** (Go).

## Frequently Asked Questions

### What types of database engines are covered in the tutorials?

The tutorials cover **key-value stores** (Redis clones), **relational databases** (SQL engines with B+Tree storage), **graph databases** (in-memory node/edge systems), and **NoSQL stores**. Specific implementations include disk-backed storage engines, persistent hash tables, and mini SQL parsers.

### Which programming languages have database tutorials available?

The repository lists database tutorials for **C**, **C++**, **C#**, **Clojure**, **Crystal**, **Go** (3 tutorials), **JavaScript**, **Python** (2 tutorials), **Ruby**, and **Rust**. This diversity allows you to learn database internals in your preferred language or compare implementations across different memory management models.

### Are these database tutorials suitable for beginners?

While some tutorials like *Let's Build a Simple Database* (C) and *DBDB* (Python) are accessible to intermediate developers, others such as the **B+Tree to SQL** Go tutorial assume familiarity with data structures, file I/O, and concurrency. Most tutorials include progressive difficulty, starting with basic storage and advancing to networking and persistence.

### Do the tutorials include networking and protocol implementation?

Yes. Several tutorials—particularly the **Redis-from-scratch** guides in C++, Go, Python, and Rust—include complete networking layer implementation. These cover socket programming, the RESP protocol, client-server architecture, and pub/sub messaging systems, providing full-stack database development experience.