Building the SQLite of Graph Data
Introduction: Why the SQLite of Graph Data Does Not Yet Exist
- What You Will Build
- Why Graph Data Needs Its Own Embedded Engine
- What This Book Is Not
- How to Read This Book
- Prerequisites
- The Journey Ahead
Chapter 1: The Embedded Graph Database Thesis
- What “Embedded” Means: No Server, No Daemon, No Network
- The Graph Workload Gap in Existing Embedded Systems
- Why SQLite Is Our North Star (And Where We Must Depart)
- Target Deployment Models and Realistic Use Cases
- Design Goals: Correctness, Durability, Locality, Small Footprint
- Non-Goals: Distributed Consensus, ML Integration, Cloud-Native Abstractions
Chapter 2: Graph Foundations for Storage Engineers
- Vertices, Edges, Directions, and the Property Graph Model
- Labels, Types, Properties: And Why They Matter for Indexing
- Multigraphs, Self-Loops, and Duplicate Semantics
- Paths, Walks, Cycles, Neighborhoods, and Reachability
- Degree Distributions and the Supernode Problem
- Graph Schemas: Enforced vs. Optional vs. Hybrid
Chapter 3: Database Internals from First Principles
- Pages, Blocks, Records, and Slots: The Vocabulary of Storage
- Fixed vs. Variable-Length Records and Slotted Page Design
- File Formats: Headers, Metadata, and Self-Description
- The Memory Stack: Application Heap, OS Cache, Database Buffer Pool
- Disk, SSD, NVMe Characteristics and I/O Patterns That Matter
- Checksums, Corruption Detection, and the Cost of Trust
Chapter 4: Architecting Graph Storage on Disk
- Adjacency Lists vs. Matrices vs. Edge Tables: The Fundamental Trade-offs
- Node-Centric Layouts: Clustering Relationships Near Their Source
- CSR/CSC-Inspired Structures for Traversal Locality
- Pointer Chasing, Offsets, and the Cost of Indirection
- Update Patterns: Appends, Deletes, Fragmentation, and Compaction
- The Reference Architecture: Why We Choose What We Choose
Chapter 5: The Binary Database File Format
- Magic Values, Version Numbers, and Byte Ordering
- Page Size Selection and Global Header Layout
- Node Records: IDs, Labels, Property Pointers, Degree Counters
- Edge Records: Source/Target References, Types, Properties
- Variable-Length Properties and Overflow Page Handling
- Free-Page Tracking, Checksums, and Corruption Invariants
Chapter 6: Identifiers, References, and Relocation
- Physical Record IDs vs. Logical Stable Identifiers
- Page/Slot Addressing and Generation Counters
- Deleted Object Reuse Without Tombstone Explosion
- Stale Reference Detection and Safe Indirection Layers
- Relocation During Compaction and Vacuum Operations
- Trade-off Analysis: Compactness vs. Durability vs. Simplicity
Chapter 7: Memory Management and Page Caching
- Page Allocation, Free Lists, and Persistent Freelist Tracking
- Buffer Pool Architecture: Pinning, Dirty Pages, Eviction
- LRU vs. Clock Algorithms: Measured, Not Assumed
- Memory Mapping: When mmap Helps and When It Hurts
- Prefetching Strategies for Traversal Locality
- Bounded Memory Usage and Graceful Degradation
Chapter 8: Indexing for Graph Data
- B+ Trees from Scratch: Pages, Splits, Merges, Search
- Hash Indexes for Equality Lookups and Constraints
- Property Indexes: Single-Key, Composite, and Inverted Structures
- Adjacency Indexes: Accelerating Neighbor Expansion
- Index Maintenance Under Transactional Updates
- Statistics, Selectivity, and Query Planner Integration
Chapter 9: Core Graph Operations and Semantics
- Node Creation, Reading, Update, and Deletion Semantics
- Edge Creation with Duplicate and Self-Loop Policies
- Property Operations: Sets, Nulls, Missing vs. Explicit Absence
- Cascading Deletes, Dangling Edges, and Referential Behavior
- Schema Constraints: Uniqueness, Type Enforcement, Validation
- Transactional Visibility of Graph Mutations
Chapter 10: Transactions from First Principles
- ACID in the Embedded Context: What It Actually Guarantees
- Transaction States: Active, Prepared, Committed, Aborted
- Lock-Based Concurrency: Granularity, Deadlocks, Starvation
- Optimistic Concurrency and Timestamp-Based MVCC
- Read Sets, Write Sets, Conflict Detection at Commit Time
- The Reference Choice: Why We Implement What We Implement
Chapter 11: Durability, Logging, and Crash Recovery
- Write-Ahead Logging vs. Rollback Journals vs. Copy-on-Write
- WAL Design: Log Records, Transaction Boundaries, Group Commit
- fsync Semantics, Durability Primitives, and OS Buffering Hazards
- Checkpoints: Materializing WAL State to the Main Database File
- Recovery Procedure: Redo of Committed, Undo of Uncommitted
- Crash Testing Infrastructure: Fault Injection and Invariant Verification
Chapter 12: Graph Traversal Primitives
- Neighbor Expansion: The Atomic Unit of Graph Traversal
- Breadth-First Search with Frontier Management and Visited Sets
- Depth-First Search, Cycle Handling, and Path Reconstruction
- Directional Filtering, Type Filtering, Property Predicates
- Memory-Efficient Traversal Over Graphs Larger Than RAM
- Distinguishing Traversal Primitives from Analytical Algorithms
Chapter 13: Query Language and Frontend
- Language Design Goals: Expressiveness vs. Simplicity vs. Familiarity
- Lexical Structure: Tokens, Keywords, Literals, Identifiers
- Grammar: Patterns, Predicates, Projections, Traversals, Mutations
- Parser Implementation: Recursive Descent with Error Recovery
- Semantic Analysis: Name Resolution, Type Checking, Validation
- Logical Query Representation and Plan Input
Chapter 14: Query Planning, Optimization, and Execution
- Logical vs. Physical Plans: Operators and Their Costs
- Cardinality and Selectivity Estimation from Statistics
- Index Selection: Scan vs. Seek Decisions for Graph Patterns
- Traversal Order Planning: Avoiding Intermediate Result Explosion
- Rule-Based and Cost-Based Optimization Rules
- Iterator Execution Engine: Volcano Model, Memory, Spilling
Chapter 15: APIs, Bindings, Tools, and Production Readiness
- Embedded API Design: Lifecycle, Transactions, Prepared Statements
- Rust Implementation and Python Bindings via FFI
- Database Shell and CLI: Querying, Inspection, Maintenance
- Security: Untrusted Files, Parser Attacks, Resource Exhaustion
- Error Model, Observability, and Tuning Guidance
- Backup, Restore, Integrity Checks, and Production Deployment