ForgeDB
A relational database engine in Java with no third-party libraries: its own SQL parser, binary records in 4 KB disk pages, an LRU buffer pool, persistent metadata and a B+ tree index. Every row is stored, found, updated and deleted by code I wrote.
One line of SQL. Seven layers of engine.
Most projects talk to a database through a driver. ForgeDB goes one layer deeper. Pick a query to see which parts of the engine it touches, and why some queries are fast.
Shell
Interactive prompt, EXEC file.sql
SQL parser
Text → immutable statement objects
Engine
Routes each statement
Catalog
Schemas, keys, indexes
Record manager
Rows ↔ binary
B+ tree index
Key → page + slot
Buffer pool
LRU pages in memory
4 KB pages on disk
students.records · students_pk.index
Every table is a chain of 4 KB pages.
Rows are encoded as fixed-length binary records. Each page starts with a 12-byte header that links it to its neighbors and counts its rows. When deletes empty a page, ForgeDB reuses it instead of growing the file.
Find one row without reading every page.
Each table gets a B+ tree on its primary key, with sorted, linked leaves and real leaf and internal splits as it grows. An equality lookup walks a few nodes instead of scanning the whole table.
Disk is slow. So keep the hot pages close.
Recently used pages stay in memory. When the pool is full, the least recently used page is evicted, and if it was changed it's written back to disk first. Click pages to read or write them.
Tested where databases usually break.
Tree splits, page boundaries, deletes and restarts are where storage bugs hide, so that's where the tests push. They run on every push with GitHub Actions.
Deep B+ tree
20,000 keys with a tiny tree order to force internal splits and root growth.
Storage stress
Rows across many pages: deletes, page reuse, a primary-key update and an index rebuild.
Restart persistence
Close the engine, reopen it, and verify every row and index survived.
End-to-end smoke
Create, insert, select, update and delete through the real parser and shell.
It's a real shell. Here's a session.
Build it with one script, no Maven required, and run java -jar build/forgedb.jar. This replays the demo from the repo.
Small on purpose. Honest about it.
ForgeDB covers the core path from SQL to bytes on disk. The features real databases add on top are the natural next steps, and the hardest ones are the ones I'd build next.
Built 08
Next 06
Not another app on top of a database. The database itself, page by page.
Job Beast
The best internships disappear fast. It finds them first.