Personal project · 2025 – 2026
PithDB / PithKV
From-scratch storage engine in Rust exploring B-tree page indexing, write-ahead logging, and crash-safe mmap key-value storage.
Personal project · 2025 – 2026
From-scratch storage engine in Rust exploring B-tree page indexing, write-ahead logging, and crash-safe mmap key-value storage.
Understanding database storage engine internals below query execution—page layouts, write-ahead log fsync semantics, and crash recovery—requires implementing storage primitives directly.
Built PithDB from scratch in safe Rust: SQL parser/VM, 4KB page cache, cursor abstraction, byte-level B-tree (leaf splits and parent separator fixups), and a WAL with commit-gated replay recovery.
Exposed configurable workload durability modes (Fast, Batch, Paranoid) after benchmarking the three-order-of-magnitude latency delta between buffered writes and fsync calls.
Pivoted to PithKV, a Bitcask mmap key-value store. Implemented CRC32 record checksums, tombstone deletions, dual-slot shadow paging for directory commits, and atomic compaction via temporary files and directory fsync.
Eliminated unsafe Rust in PithDB and restricted unsafe calls in PithKV to raw mmap memory bindings, relying on compiler guarantees for memory safety.
Exposed explicit durability tiers to callers, allowing applications to trade fsync latency for write throughput based on workload requirements.
Committed key-value directory metadata across two checksummed slots with an active-slot flip, ensuring atomic recovery even if power fails mid-write.
Compacted append logs into temporary files, executed atomic renames, and issued fsync calls on parent directories to ensure metadata durability.
Built test suites that inject bit corruptions into CRC headers and execute concurrent operations to verify recovery logic.
Two storage engines operating with verified crash recovery protocols—WAL replay and dual-slot CRC shadow paging—validated against automated corruption testing.