Why Build a Database?
Not to replace PostgreSQL. To understand it. Every backend developer queries databases daily, but few understand what happens between SELECT * FROM users and the data appearing on screen.
The Storage Engine
At its core, a database is a fancy file. My storage engine uses 4KB pages organized in a B-tree structure. Each page holds multiple rows, and the B-tree keeps them sorted by primary key for efficient lookups.
The Buffer Pool
You cannot read from disk for every query. The buffer pool keeps frequently accessed pages in memory and uses an LRU eviction policy when memory is full. Getting this right was the single most impactful optimization.
Write-Ahead Logging
Before any modification hits the actual data files, it goes to the WAL. This ensures that even if the process crashes mid-write, the database can recover to a consistent state on startup.
What I Took Away
Building a database taught me more about systems programming than any course. It connected the dots between data structures, operating systems, and the real-world performance characteristics I see every day.