Guided journey · educational simulator

Build AtlasDB

Not a database product — a way to understand one. atlas.db starts as a flat file and grows one mechanism at a time. Every version exists because the previous version broke under a specific load; read the “problem” first, then the change, then why it will not be enough.

  1. V0Flat File
  2. V1Records
  3. V2Pages
  4. V3Slotted Pages
  5. V4Index
  6. V5B+ Tree
  7. V6Buffer Pool
  8. V7Write-Ahead Log
  9. V8Transactions
  10. V9MVCC
  11. V10Query Engine
  12. V11Replication
atlas.db · version 0

V0 Flat File

atlas.db is one file; every write appends a line, every read scans it.

atlas.db
────────────────────────────
1,alice,alice@example.com
2,bob,bob@example.com
3,carol,carol@example.com
…
Why start here
  • There is no database yet — only data that must outlive the process. A file is the smallest thing that survives a restart.
What this version adds
  • A text file. `INSERT` appends a line; `SELECT … WHERE id = 3` reads from the top until it finds the line.
  • Everything is a byte sequence: the schema is implicit in the column order.
Where it will break next
  • Reading is O(file). A 10 GB file means 10 GB of reads for one row.
  • An update rewrites the whole file; a crash mid-rewrite loses everything.
  • Nothing says where one row ends and the next begins except a newline you hope no value contains.
Lessons for this version
The real thing

Every database begins as bytes in files. PostgreSQL keeps one file per table segment under `base/<dboid>/`; SQLite keeps the whole database in one file.

From table to SSD: the storage hierarchy

The simulator for this version. Numbers are modelled for teaching, not measured from a real engine.

From a table to the SSD
Seven layers, each a different unit. SQL sees the top three; the engine works in the middle two; the OS and the device own the bottom two. Click a layer.
logical ↑ · physical ↓
PagesGeneral database concept

The fixed-size unit the engine reads, writes, caches and locks. A page has a header (checksum, free-space pointers), a slot directory and the records. A record is addressed as (page number, slot).

Concrete example (users table, page #4821)
Page #4821 holds Alice at slot 3 together with ~100 other records; 8192 bytes, 24 B header, ~410 B free.
Typical size
8 KB (PostgreSQL) · 16 KB (InnoDB)
Unit
unit of I/O and of the buffer pool
Rough latency
in cache ≈ 100 ns per access
The page is the layer everything else is measured in. Buffer pool hit rates count pages, EXPLAIN reports pages (Buffers: shared hit=…), a checkpoint writes pages, a lock protects a page. Reading one 77-byte record costs the same 8192-byte read as reading all hundred on the page.
Conceptual model — sizes and latencies are typical figures, not measurements; file paths follow PostgreSQL conventions.