Architecture Overview
This section explains how LatticeDB's storage engine works, from the ground up. Each chapter builds on the previous, showing how simple primitives combine to create a durable, transactional graph database with vector search, full-text search, and local event streams.
The Stack
Chapters
Storage Engine
- Virtual File System - Abstracting file I/O for portability and testing
- Portable Databases - Serializing to bytes, and running with no files at all
- Page Manager - Fixed-size pages, allocation, and checksums
- Buffer Pool - Caching pages in memory with eviction
- B+Tree - Ordered key-value storage with efficient lookups
Durability & Transactions
- Write-Ahead Log - Durability through logging before data changes
- Transaction Manager - ACID transactions with begin/commit/abort
- Checkpointing - Bounding recovery time by flushing dirty pages
- Recovery - ARIES-style crash recovery with redo/undo
Data Model
- Graph Storage - Nodes, edges, labels, and properties
- Durable Streams - Transactional event records and semantic graph changes
Search Indexes
- Vector Search - HNSW approximate nearest neighbor search
- Full-Text Search - BM25-scored inverted index, per-property declarations, and search as an access path
Query System
- Query Execution - Volcano iterator model, operators, and planning
Design Principles
Direct Page Manipulation
We don't deserialize pages into objects. Instead, we read/write bytes directly in page buffers. This is "zero-copy" - no intermediate representations, no serialization overhead.
Everything is Pages
The entire database is built on fixed-size pages (4KB by default):
- B+Tree nodes are pages
- Large B+Tree values spill into linked overflow pages
- WAL frames are pages
- The file header is a page
- Free list entries are pages
This uniformity simplifies the system - one caching layer, one I/O path, one checksum format.
Durability Through WAL
Changes are logged before being applied. This means:
- Commit = log is on disk (fast, sequential write)
- Actual data pages can be written lazily
- Crash recovery replays the log
Simple Concurrency Model
Each page has a reader-writer latch. Multiple readers OR one writer. No complex lock hierarchies - simplicity over maximum concurrency.