A Hands-On Guide to Storage, Concurrency, Query Processing and Reliability in Systems Programming
Chapter 1: Why Build a Database?
- The Hidden Complexity of Every Database Query
- What You Will Build and Why It Matters
- A Tour of the Architecture We Are Going to Construct
- Implementation Roadmap: From Empty Project to Working Database
- How to Read This Book and Use the Code
Chapter 2: Project Setup and Systems Foundations
- Choosing Rust for Database Implementation
- Project Structure and Build Configuration
- Core Abstractions: Pages, Records and Offsets
- Error Handling Strategy Across the Engine
- First Binary: Initializing an Empty Database File
Chapter 3: Storage Fundamentals - Disks, SSDs and Pages
- How Disks and SSDs Actually Work
- Why Databases Think in Pages, Not Bytes
- Building Our Page Abstraction Layer
- Binary Data Layout: Endianness, Alignment and Serialization
- Implementing the Storage Manager Interface
Chapter 4: File Format and Slotted Page Records
- Designing the Database File Format
- Slotted Page Layout: Headers, Directories and Records
- Variable-Length Record Serialization
- Free-Space Management Within Pages
- Implementing Page Reads and Writes with Verification
Chapter 5: Buffer Pool Manager - Caching at Scale
- The Purpose of Buffer Pools and Why They Are Hard
- Pinning Semantics and Reference Counting
- Dirty Pages, Write Policies and Flush Behavior
- Handling Memory Pressure and Eviction Under Load
Chapter 6: Logging, Durability and Crash Recovery
- The Durability Problem and Why fsync Matters
- Write-Ahead Logging: Protocol and Invariants
- Designing Our Log Record Format
- Checkpointing Strategies and Implementation
- Crash Recovery: Redo and Undo in Practice
Chapter 7: Indexing - B-Trees, Hash Indexes and Beyond
- Why Indexes Exist and What They Trade Away
- Implementing a B+ Tree from Scratch
- Page Splits, Merges and Concurrency Considerations
- Hash Indexes for Equality Lookups
- LSM Trees and Alternative Index Architectures
Chapter 8: Transactions and Concurrency Control
- ACID Properties: What They Mean in Implementation Terms
- Locking Protocols and Two-Phase Locking
- Deadlock Detection and Prevention
- Latches vs Locks: Protecting Data Structures
- Implementing MVCC with Snapshot Isolation
Chapter 9: SQL Parsing and Semantic Analysis
- Designing Our SQL Subset and Grammar
- Lexical Analysis: Tokenizing SQL Input
- Recursive Descent Parsing and AST Construction
- Symbol Tables and Schema Resolution
Chapter 10: Query Planning and Cost-Based Optimization
- From AST to Logical Plan
- Physical Operators and Execution Strategies
- Building a Cost Model from Statistics
- Cardinality Estimation: Histograms and Selectivity
- Join Ordering and Query Rewrite Rules
Chapter 11: Query Execution Engine
- Operator Architecture: Iterators and Pipelining
- Table Scans and Index Scans
- Filtering, Projection and Expression Evaluation
- Join Implementations: Nested-Loop, Hash and Merge
- Aggregation and Grouping with Hash Tables
Chapter 12: Performance Engineering and Optimization
- Understanding Database Performance Characteristics
- I/O Patterns: Sequential Versus Random Access
- Cache Efficiency and Data Locality
- Vectorized Execution vs Tuple-at-a-Time Processing
- Profiling, Benchmarking and Workload Generation
- Systematic Optimization: Finding and Fixing Bottlenecks
Chapter 13: Reliability, Correctness and Failure Handling
- Crash Consistency: Guarantees and Invariants
- Torn Pages and Partial Writes
- Corruption Detection with Checksums and Validation
- Disk-Full Conditions and Safe Failure Modes
- Backup, Restore and Integrity Verification
Chapter 14: Beyond Single Node - Distributed Database Concepts
- Why Single-Node Databases Eventually Hit Limits
- Replication Architectures: Leader-Follower and Multi-Leader
- Log Replication and Consistency Models
- Sharding and Distributed Query Execution
- Consensus, Fault Tolerance and Rebalancing
Chapter 15: Conclusion - From Educational Engine to Production System
- Architecture Review: How All Subsystems Fit Together
- What We Simplified and Why Production Systems Differ
- Comparing Our Implementation to Real Databases
- Paths Forward: Extending Your Database Engine
- The Engineer’s Mindset for Building Reliable Systems