A single-node, embedded, crash-safe key–value database implemented in C++, inspired by real-world LSM-tree storage engines (LevelDB / RocksDB internals).
This project focuses on core database internals:
- Write-Ahead Logging (WAL)
- MemTable / Immutable MemTable
- SSTable (Sorted String Table)
- Crash recovery
- Tombstone-based deletes
No networking. No SQL. No distributed complexity.
Just correct storage-engine fundamentals.
The database is not a linear pipeline.
It is a layered, event-driven system with short-circuit read paths and out-of-band maintenance.
- Append operation to WAL
fsync()→ durability commit point- Update MemTable
- When MemTable reaches size threshold:
- Freeze it as Immutable MemTable
- Create a new empty MemTable
- Flush Immutable MemTable to an SSTable
Reads short-circuit through layers:
- MemTable
- Immutable MemTable
- SSTables (newest → oldest)
Search stops immediately on:
- Value found
- Tombstone found
- Append-only binary file
- Stores PUT and DELETE operations
fsync()defines the commit boundary- Used only for crash recovery
- In-memory ordered map
- Stores latest key states
- Deletes stored as tombstones
- Fast reads and writes
- Read-only snapshot of a full MemTable
- Allows writes to continue without blocking
- Flushed to disk as an SSTable
- Immutable, binary, sorted on-disk file
- Stores final key states
- Includes:
- Data blocks (sorted key-value records)
- Sparse index (key → offset)
- Footer (index location)
On startup:
- Discover existing SSTables
- Open WAL
- Replay WAL records sequentially
- Rebuild MemTable
- Resume normal operation
Partial WAL records are safely ignored.
put(key, value);
get(key);
del(key);