all projects

// RESEARCH

MiniDB

A transactional SQL database engine in Go

GoLSM TreesWALMVCCSQL ParserDatabase Internals

Overview

MiniDB is a database engine built from scratch in Go to demonstrate the moving parts of a real RDBMS — storage, durability, concurrency, indexing, and query execution — without the abstraction layers that hide them in production systems.

Storage: LSM Tree

  • MemTable for fast in-memory writes
  • SSTables on disk, sorted and immutable
  • Background compaction merges SSTables to reclaim space and improve read performance
  • Optimised for write-heavy workloads

Durability: Write-Ahead Logging

Every mutation is appended to the WAL before being applied to the MemTable. On restart, the WAL is replayed — no committed write is ever lost, even after a crash.

Transactions: ACID via MVCC

  • Multi-Version Concurrency Control — each transaction sees a consistent snapshot
  • Snapshot Isolation — readers don't block writers, writers don't block readers
  • Full ACID guarantees

Query layer

  • Custom SQL parser supporting SELECT, INSERT, and WHERE clauses
  • Hash index for O(1) primary-key lookups
  • Execution engine with a clean interpreter pattern

Interfaces

  • Interactive REPL for ad-hoc exploration:
    minidb> INSERT INTO users VALUES (1, 'Alice')
    minidb> SELECT * FROM users WHERE id = 1
    [1 Alice]
  • TCP server mode for client–server use

Why build it

Reading about LSM trees, MVCC, and WAL gives you the concepts. Writing one from scratch is what makes them stick — the failure modes, the trade-offs in compaction strategies, the subtle bugs in snapshot isolation are only visible when you live inside the implementation.