← pagedb · the tracker

How pagedb works

A database whose base lives in R2 as immutable pages, served by one Durable Object that only ever holds what queries touch. Every list, board column and thread in the tracker is a live query: when anyone writes, the object works out exactly which rows of which open views changed and pushes just those.

Our take on r2db, rebuilt from its public behaviour and built to be measured. The engine is Rust compiled to WebAssembly (the same code builds the dataset natively); the object, sync protocol and UI are TypeScript.

1 · Four tiers, one object

A page is a 64 KiB block of one B+tree. When a query needs a page, it looks in each tier in turn:

RAM (in the engine)A fixed 32 MiB budget inside the WebAssembly heap.< 1 µs
The object's SQLitePages it has fetched before, plus every tree's interior pages. Synchronous, survives hibernation.~µs
Cloudflare cache, same cityThe base is immutable, so 1 MiB chunks can be cached at the object's location.10–30 ms
R2The base: 4 MiB parts. A page's id is its position, so its location is arithmetic.170–370 ms

2 · A read never waits halfway

The engine can't wait for R2 in the middle of a query (WebAssembly calls are synchronous). So when a query needs a page no synchronous tier holds, it records it and keeps going, collecting every page the query will need, then hands the whole list back. The object fetches them as a few coalesced 1 MiB reads (at most 6 at once, a Durable Object limit) and runs the query again.

3 · A write updates the views it affects

Writes don't touch the base. They go into an overlay of index entries in the object's SQLite (durable when acknowledged, like any Durable Object write), and reads merge the base with the overlay. Counts stay instant: each overlay entry carries its effect on the row count.

Each open query is a window of keys. For every write, the engine computes, for each window, which rows enter, leave or change (and refills a window from the index if rows left it). This is done without changing anything: if a page is missing, the whole write is retried once it's fetched, so a push can never half-apply. Then the overlay and every window commit together, and each socket gets one message with its changes.

The tracker applies your edits optimistically: they show instantly, and are reconciled when the server's update (at or after your write's version) arrives. r2db's demo waits for the server.

4 · You can only ask for what the app allows

Every list, column and thread is a named query (issues of a project with these filters; a count; an issue's thread). The page asks the Worker for a lease. The Worker checks the arguments, builds the query and signs it (HMAC, valid for 60 s, bound to this database). The socket subscribes with the lease, and the object only runs a query it can verify it signed. So a visitor can't send a query that scans 100 GB, reads another database, or skips a limit. The first view's leases come inside the HTML, so they cost no extra round trip. Writes work the same way: named mutators, validated by the Worker.

5 · Four apps, one engine

The schema is data: tables, indexes and relations live in each base's manifest. The same engine and the same Durable Object code serve four databases:

6 · Search by meaning, in the same pages

Semantic search on Hacker News runs in the same object as everything else. Every story since 2006 is an embedding (Workers AI, Qwen3-Embedding-0.6B, 1024 dimensions) in a vector index made of ordinary B+trees: one keyed by cluster, story id, whose entries hold 1 bit per dimension of the story's vector (for a fast first pass) or an 8-bit code and the columns a result shows (to rerank the best candidates), and a small tree of cluster centroids that sits in the pinned region.

7 · Measured

Measuredpagedbr2db demo
Issues on screen after opening the page (both 100 GB bases, same laptop, median of 8 loads)0.25 s1.09 s
Every list, board column and count query from cold (100 GB)1 fault roundrounds = dependency depth
Warm queries from a laptop (100 GB)35–49 ms—
Count of a project's issues3.6 µs engine time3 ms (their published number)
Your own edit visibleinstant (optimistic)after the server round trip
Object waking from sleep (1 GB base)~0 ms of I/O (state in its SQLite)—
Write → other tabs, 1,000 sockets, 5 writes/s (1 GB base)p50 255 ms, p99 684 ms (laptop ↔ Cloudflare both ways)—

Semantic search (all 4.85 million HN stories, compared with Cloudflare Vectorize on the same vectors):

MeasuredpagevecVectorize
Recall@10 against exact search (100 queries, same vectors)0.9710.786
Search, new query (p50 in the Worker)138 ms (SQLite), 44 ms (RAM)465 ms
Search with a date filter (~8% of stories)140 ms, recall 0.8910.2 s, recall 0.72
Search, cold1.86 s from R2, 0.58 s from the city cache—
A write is searchableon the next searchafter 1–66 s (p50 14 s)
Results update liveyesno
Monthly cost at this size, before queries~$1.50~$52

Comparisons are against r2db's public demo, measured the same way from the same laptop, both on 100 GB bases (r2db as a returning visitor with its intro panel closed). The tracker runs on the 100 GB base (27.1 million issues, 1.47 million pages): every query is still one fault round and warm queries take 35–49 ms from a laptop. Size changes only how often a page is already cached, and a brand-new object's one-time start (it loads 73 MB of interior pages, 0.2–2 s).

8 · The same object in a container

The database object is ordinary Durable Object code, so it also runs inside workerd in a Cloudflare Container (4 vCPU, 12 GiB). There it gets a 6 GiB page tier instead of 32 MiB and a dedicated CPU. Measured on the 10 GB base: warm queries are the same (~45 ms from a laptop), and fan-out to 1,000 sockets is about twice as fast (write → every tab: p50 128 ms vs 255 ms; p99 296 ms vs 684 ms). The trade-offs: a container takes at most 4,096 connections, its cold start takes seconds, and it reaches R2 through a bridge.

9 · Limits (honest list)

10 · Layout

engine/core     Rust: codec, 64 KiB pages, B+tree, overlay, queries, writes, IVM, vector search (tests: oracle + fault-injection fuzz)
engine/wasm     the engine as WebAssembly for the Durable Object
engine/builder  native: generates the dataset, writes 4 MiB parts (runs in a Cloudflare Container for 100 GB)
src/do.ts       the Durable Object: tiers, fault rounds, sockets, overlay persistence
src/app.ts      the tracker's named queries and mutators
src/lease.ts    signed queries (leases)
web/            this site