Purpose: before M0/M1 code starts, settle the
architecture decisions in PROD_PLAN.md that are expensive
to reverse. Each section covers:
the question and why it matters for our goals (§1–2 of the
plan);
every serious option, with pros and cons;
the evidence: benchmarks, incidents, statistics, and our own
measurements;
my recommendation, and what would change my mind.
How to answer: write a short reply after each
**My comment:** line. "Agree" is fine; so is "go with
option B" or a question. When you're done, ask me to re-read this file.
I'll then update PROD_PLAN.md to match.
Evidence labels:
[src] — a primary or reputable source, linked in
§Sources.
[vendor] — published by a party with a commercial
interest.
[ours] — measured on this machine against the
current prototype (2026-11-25).
[mem] — from my own knowledge, not re-verified for
this document. Treat it as a claim to check.
Ordering: decisions are ordered by cost of reversal,
most expensive first. Sections Q1–Q4 at the end only need a quick
yes/no.
D1.
ADR-01 — Storage model (how rows and their old versions are stored)
The question
Where does the current row live? Where do old versions live (for MVCC
readers and rollback)? How do indexes point to rows? And who cleans up
old versions? This decision shapes:
write amplification, space use and bloat;
hot-row behaviour;
whether there is "maintenance" (VACUUM/sweep);
index design, recovery design and the code size of half the
engine.
Why it matters for our goals
The tenets are zero maintenance,
predictable (no bloat cliff) and cheap
(low write amplification). E-commerce adds a specific stress:
hot rows (inventory counters, flash sales) that are
updated thousands of times a minute.
What we measured on
today's design [ours]
Today's design is Firebird-style: versions are kept in the heap,
there is no sweep yet, and an index entry is added per version.
Measurement
Result
One row updated ~3,500 times
139 KB of heap + 155 KB of index for one logical
row
WAL volume
~8.5 KB per single-row update (34 MB total)
Visibility cost
Every read of that row walks the version chain
Without a sweep, this grows forever. With a sweep, it becomes
PostgreSQL's VACUUM problem.
Options
Option
A — Keep the Firebird model: versions in the heap, plus sweep
(current)
How: each UPDATE writes a new full row version into
the table pages, linked to the previous one. Every version gets index
entries. A sweep/garbage-collection pass removes dead versions
later.
Who: Firebird.
Pros:
It already exists and is tested.
Rollback is instant: just mark the transaction dead.
No undo log to write or read.
Cons:
The same structural problems as PostgreSQL (option B): bloat between
sweeps, and index entries per version. Our measurement above shows
both.
Firebird's well-known operational issue is a long-running
transaction holding back the "oldest interesting transaction", so
garbage piles up and performance degrades until the sweep can run
[mem].
It contradicts "zero maintenance".
Option B
— PostgreSQL model: append-only heap, VACUUM, HOT
How: the same idea as A. PostgreSQL adds HOT
(heap-only tuples): if no indexed column changed and the page
has free space, the new version is chained on the same page with no new
index entry.
Who: PostgreSQL. Aurora PostgreSQL also keeps this
storage model [src: Pavlo].
Pros:
Proven at enormous scale; simple rollback; readers never touch an
undo log.
Old versions sit on the same page, so time travel and long readers
are cheap.
Cons, with evidence:
Pavlo & Zhang, CMU/OtterTune (2023), "The Part of
PostgreSQL We Hate the Most" [src] explain why they consider
PostgreSQL's MVCC its worst part: append-only version storage,
version-chain traversal for the latest version, index entries per
physical version (5 versions → up to 5 index entries), and vacuum
management.
Uber (2016), "Why Uber Engineering Switched from Postgres to
MySQL" [src]: because PostgreSQL indexes point at physical
tuple locations, an update that moves a tuple rewrites every
index. That write amplification also flows into replication, since
replicas replay the same WAL.
Counterpoint [src]: Markus Winand, Simon Riggs and Robert Haas
published rebuttals showing many of these issues are addressable. The
analysis was based on PostgreSQL 9.2.
Transaction ID wraparound outages:
Mailchimp/Mandrill (Feb 2019) [src]: a write spike
on one of 5 PostgreSQL instances triggered wraparound protection.
Recovery required standalone mode + VACUUM; the outage ran roughly 2
days, and Mailchimp refunded affected customers. Their engineers had
flagged the risk in November 2018 and put a monitoring ticket in the
backlog.
Sentry (2015) [src] had a similar wraparound
incident: "your only option is to stop accepting writes and
vacuum".
Note: our 64-bit transaction IDs remove wraparound, but not
bloat.
Verdict for us: the same as A, plus decades of
tuning folklore.
The version storage scheme is "one of the most important components"
for MVCC scaling.
Delta storage (keep the master version in place, deltas of
only the modified attributes elsewhere) "performs well for transactional
workloads, especially if the fraction of modified attributes is
small".
Its weakness is scan-heavy analytical reads, which are not our
primary workload.
Vendor benchmark: Supabase's OrioleDB on a
TPC-C-derived workload [vendor]:
~1.8× more transactions per minute than PostgreSQL's heap at 8XL
size; ~13% ahead at Large and ~29% ahead at 8XL in another post.
The heap won at Small size.
Supabase says the gains are biggest on frequently updated
tables.
Treat these as directional; they are vendor-run.
Non-key updates touch no secondary index. That
kills Uber's write-amplification complaint, and inventory decrements
become a tiny undo record plus an in-place change.
No table-wide VACUUM. Purge work is proportional to
changes, not table size.
PK locality: range scans by PK, and good insert
locality with time-ordered keys (UUIDv7 or bigint identity).
Time travel (AS OF, feature F-07)
falls out of the undo log.
Cons:
Secondary-index lookups do two B+tree descents
(secondary → PK → row). Mitigations: covering indexes
(INCLUDE) and index-only scans.
Random PKs (UUIDv4) cause page splits and
fragmentation in clustered tables. This is a well-known InnoDB
pain [mem]. Mitigation: default to uuidv7() or bigint
identity, and warn on v4 PKs.
Purge lag is still possible. Long-running
transactions keep undo alive:
InnoDB's "history list length" grows. MySQL docs name
mysqldump --single-transaction and forgotten open
transactions as typical culprits [src].
AWS Aurora documents that a large history list slows queries and
shutdowns [src].
So undo-based MVCC does not eliminate the
long-transaction problem; it moves it from table bloat to undo growth.
Our answer (ADR-02): bounded undo retention, an explicit
72000 snapshot too old error, idle-in-transaction timeouts
on by default, and visibility of who is holding purge back.
Rollback costs O(changes): the undo must be
applied. Huge transactions roll back slowly, and crash recovery has an
undo phase.
More complex recovery (ARIES-style redo +
undo).
Wide PKs bloat every secondary index, since each
secondary entry carries the PK.
Option
D — Heap table, in-place update, undo log; indexes point to a stable row
id
How: like C, but rows live in an unordered heap at
a stable row id, and every index (including the PK) points to that row
id. Updates are in place, with undo for old versions.
Who:
Oracle (heap-organised tables, the default; index-organised tables
are optional).
zheap, EnterpriseDB's undo-based storage for PostgreSQL. It stalled
and was never merged, which shows that retrofitting undo is hard
[mem].
Pros:
A secondary lookup is one descent plus a direct row
fetch.
No double lookup, and the PK index isn't special.
Non-key updates still touch no index, as long as the row stays at
its row id.
Cons:
Growing rows that no longer fit need forwarding pointers ("row
migration/chaining"), which adds an extra I/O and has to be cleaned up
[mem].
A heap needs its own free-space management.
No PK locality (range scans by PK are random I/O).
Two space managers (heap + indexes) instead of one (B+trees
only).
Verdict: a serious runner-up. It wins on
secondary-index-heavy lookups and loses on PK range scans and
simplicity.
Option E — LSM tree
(log-structured merge)
How: writes go to an in-memory table, then are
flushed to sorted immutable files; background compaction merges
files.
Facebook moved its main user database (UDB) from InnoDB to
MyRocks and reported about 50% less storage than
compressed InnoDB (completed August 2017, about a year
of work) [src]. A later talk cited 2× vs compressed and 4× vs
uncompressed [src].
Cons:
Read amplification: point reads may check several levels (bloom
filters help).
Compaction consumes CPU and I/O and can cause latency stalls.
RocksDB has a very large tuning surface [mem].
Delete-heavy workloads leave tombstones.
Much more code.
Facebook's driver was flash cost at hyperscale, which is not our
segment.
Verdict: wrong trade-off for a small, predictable,
zero-tuning OLTP engine.
Option F — Copy-on-write
B+tree, no WAL
How: every commit writes new copies of the modified
path up to a new root, then atomically switches the root.
Who: LMDB, bbolt/BoltDB.
Pros:
Crash safety is trivial: no WAL, no recovery.
Readers never block and need no locks.
Extremely fast reads.
Cons:
One writer at a time. The whole database serialises
writes [mem].
Path copying on every commit means write amplification.
Free pages can't be reused while old readers live.
Verdict: great for embedded read-mostly stores;
unfit for concurrent OLTP writes.
Summary matrix (✔
good, ~ ok, ✘ bad for our tenets)
Zero maintenance
Hot rows
Write amplification
Space predictability
Secondary lookups
Code size
Proven
A Firebird
✘
✘
✘
✘
~
✔ (exists)
✔
B PostgreSQL
✘
✘
✘
✘
✔
~
✔
C Clustered + undo
✔ (bounded purge)
✔
✔
~ (undo, bounded)
~ (double lookup)
~
✔ InnoDB
D Heap + undo
✔
✔
✔
~ (row migration)
✔
~
✔ Oracle
E LSM
~ (compaction)
~
✔
~
~
✘
✔
F CoW B+tree
✔
✘ (single writer)
✘
~
✔
✔
✔ LMDB
Recommendation
Option C. It best serves zero maintenance, hot rows
and low write amplification, it has the most production evidence
(InnoDB), and the research supports delta storage for OLTP.
What would change my mind: if the target apps are
dominated by lookups on non-PK indexes with very wide PKs, D
becomes more attractive. For typical e-commerce schemas (bigint/UUIDv7
PKs, lookups by PK or by a few secondaries), C wins.
Sub-decisions
D1.a Tables without a PK get a hidden 8-byte row
id. This is what InnoDB does [mem]. Alternative: require a PK, i.e.
refuse CREATE TABLE without one, or warn.
D1.b Default PK guidance: warn when a PK is
uuid with v4 values, and recommend uuidv7() or
identity.
✎ My comment (D1 option):
✎ My comment (D1.a hidden row id vs require PK):
✎ My comment (D1.b PK guidance):
D2. ADR-12
— Implementation language (C vs Rust vs Zig)
The question
This is the cheapest moment ever to switch. The
prototype is ~5.8k lines, and M2 rewrites most of the storage anyway. In
12 months it will be ~50k+ lines, and switching will be effectively
impossible.
Evidence
Memory-safety bugs dominate security issues in
C/C++:
Microsoft MSRC (2019): ~70% of the vulnerabilities
Microsoft assigns a CVE are memory-safety issues, a share that has held
stable for over a decade [src].
Google Android (Nov 2025): memory-safety bugs fell
below 20% of Android vulnerabilities in 2025 for the
first time, as new code moved to Rust. Google reports a ~1000×
lower memory-safety vulnerability density in Rust vs Android's
C/C++, and a ~4× lower rollback rate for medium/large Rust changes
[src].
C can be extremely reliable, but at a price:
SQLite is C and is famously reliable.
Its proprietary TH3 harness achieves 100% branch and 100% MC/DC
coverage. The project has hundreds of times more test code than library
code (590× in one snapshot, ~92 MSLOC of tests vs ~156 KSLOC of core)
[src].
The SQLite docs themselves call maintaining 100% MC/DC "laborious
and time-consuming" [src].
Databases already written in each language:
C: SQLite, PostgreSQL, Redis, LMDB.
Rust: TiKV, Neon's storage, Materialize,
RisingWave, Databend; Turso's rewrite of SQLite in Rust [mem].
Zig: TigerBeetle (financial transactions DB, with
deterministic simulation testing). Jepsen analysed TigerBeetle 0.16.11
[src: Jepsen report listed in FDB search].
Database cores need unsafe even in
Rust. Buffer pools, latches, page byte layouts and raw I/O
buffers require unsafe blocks [mem]. Rust's guarantee
shrinks there, but the unsafe surface becomes small and auditable, and
everything above it (SQL, planner, executor, protocol, catalog) is
safe.
Options
Option A — Stay in C11
(current plan)
Pros:
Continuity: 5.8k lines and all tests are kept.
libc-only, tiny static binaries.
A natural C ABI for embedded mode (ADR-11).
Fast compiles; full control of layout and allocation.
Every platform and toolchain; easiest SIMD intrinsics.
You are already working in it.
Cons:
Memory-safety and data-race bugs are found only by tests:
sanitizers, fuzzing, simulation. Each is caught late, and some
(use-after-free under concurrency) are hard to reproduce.
The plan's §9 test investment is mandatory, not optional.
Contributor safety: every contributor can introduce memory
corruption.
Option B —
Rust (core and server), C ABI for embedding
Pros:
Memory safety and data-race freedom at compile time for most of the
code.
Strong typing for protocol, SQL and plan code.
cargo test/fuzz tooling.
Evidence of a large defect reduction in practice (Android).
The C ABI via extern "C" keeps embedded mode
possible.
Cons:
Rewrite cost now: ~3–5 weeks to port the prototype, or start fresh
at M2.
A learning curve if the team is new to Rust.
unsafe is still needed in the storage core.
Dependency discipline is required: avoid tokio and pulling half of
crates.io.
Compile times; binary size a bit larger (still well under 15 MB)
[mem].
Fine-grained SIMD is possible but more verbose.
Option C — Zig
Pros:
C-like control with explicit allocators.
Bounds and overflow checks in safe builds.
comptime; excellent C interop and
cross-compilation.
Proven in TigerBeetle.
Cons:
Pre-1.0 language with breaking changes between
releases [mem].
No compile-time memory-safety guarantee (use-after-free is still
possible).
A smaller ecosystem and hiring pool.
Option
D — Hybrid: C core + Rust for parsers, protocol and planner
Pros: the riskiest input-facing code (wire
decoder, SQL parser, JSON) becomes safe; the storage core stays C.
Cons: two toolchains and an FFI boundary in the hot
path; ADR-12's "one toolchain" goal is lost.
Recommendation
There's no single "right" answer here; it depends on your
team's Rust comfort.
If you or your team are comfortable in Rust:B, and make the switch now, before M1. The evidence on
defect rates is strong, and the window is closing.
If not:A. C is viable, as SQLite
proves, but only with the full §9 safety net: sanitizers on every PR,
fuzzing every decoder, and simulation.
I'd avoid C (Zig) until it reaches 1.0, and D (hybrid) because of the
complexity.
✎ My comment (language + your/team Rust
experience):
D3.
ADR-07 — What happens to a transaction after a statement fails
The question
Inside BEGIN … COMMIT, a statement fails (for example a
unique violation). Is the whole transaction now dead
(PostgreSQL), or is only that statement undone, with the
transaction continuing (Oracle, SQL Server, MySQL)?
Evidence
PostgreSQL:
After any error, every further statement fails with
25P02 current transaction is aborted, and
COMMIT returns ROLLBACK.
Partial work can be kept only via explicit
SAVEPOINT.
Demand for statement-level rollback on PostgreSQL:
pgjdbc added autosave=conservative|always, which wraps
each query in a savepoint so a failure can roll back to it [src].
The pgjdbc maintainer warns that this "comes with a performance
penalty" and recommends retrying transactions instead [src].
A 2017 pgsql-hackers "Statement-level rollback" proposal was
discussed but not merged [src].
psql has ON_ERROR_ROLLBACK for interactive use
[mem].
Savepoint cost on PostgreSQL: subtransactions
beyond 64 per transaction overflow the per-backend cache and can cause
severe contention. GitLab published a widely cited post about removing
subtransactions for this reason (2021) [mem]. Our undo design can make
savepoints cheap (just an undo position), so the performance argument
against statement-level rollback mostly disappears for us.
Other engines:
Oracle and DB2 roll back just the failed statement [mem].
SQL Server rolls back the statement for most errors when
XACT_ABORT is OFF (the default) [mem].
MySQL InnoDB rolls back the statement for most errors, but a
deadlock rolls back the whole transaction [mem].
The safety
argument I under-weighted in the plan
With statement-level rollback, an application that ignores an
error and then commits will commit the rest of the
transaction: partial work. Under PostgreSQL semantics, the same
buggy code is protected, because COMMIT becomes ROLLBACK. PostgreSQL
apps are written with that safety net in mind, for example
try { … } finally { commit(); } patterns.
Code written for PostgreSQL that catches errors already uses
savepoints (Django's nested atomic(), Rails
requires_new), and it works under both modes. So
statement-level rollback helps new code but can silently
weaken existing PostgreSQL code.
Options
Option A — PostgreSQL
semantics only
Pros: exact compatibility and the fail-safe
behaviour above.
Cons: keeps the most-complained-about PostgreSQL
behaviour, and the current prototype's working feature is thrown
away.
Option
B — Statement-level rollback by default, PostgreSQL mode opt-in (the
current plan)
Pros: developer-friendly, Oracle/SQL Server-like,
removes a classic PostgreSQL gotcha.
Cons: silently weakens the safety net for
PostgreSQL-targeted apps (above). It's also a behavioural difference
users hit only when something has already gone wrong, which is the worst
time to discover it.
Option
C — PostgreSQL semantics by default; statement-level rollback opt-in,
plus cheap savepoints
How: opt in with
SET on_error = 'statement' per session, or per
role/database. Savepoints cost nothing extra and there is no
subtransaction limit.
Pros: safe by default and fully compatible; anyone
who wants the friendlier mode turns it on with one setting; drivers stay
correct.
Cons: the "out of the box" developer experience is
PostgreSQL's, not "better".
Recommendation (changed
from the plan)
Option C. Compatibility and fail-safety beat
convenience; that is tenet 1 (correct) over tenet 7 (loved). Our real
differentiator is that savepoints and the opt-in mode are cheap and
unlimited, and PostgreSQL can't offer that. If you agree, C-05/F-11
in the plan get reworded.
✎ My comment:
D4. ADR-02 — Concurrency
control choices
D4.a — How snapshots are
taken
Option 1 — Active-transaction list (PostgreSQL).
A snapshot copies the list of in-progress transaction IDs.
Evidence: Andres Freund's 2020 analysis of
PostgreSQL connection scalability [src] found:
snapshot computation (GetSnapshotData()) scanning all
backends was the most pressing scalability limit;
per-connection memory was less of a problem than believed
(< 2 MiB with huge pages in many workloads).
PostgreSQL 14 optimised it.
Pros: simple, well understood; visibility needs no
extra lookup.
Cons: snapshot cost grows with connection count,
which matters for our 10k-connection goal.
A snapshot is a single number, so it costs O(1) regardless of
connections.
Pros: scales with connections; snapshots are
trivial to store and compare; natural for AS OF queries and
for replicas.
Cons:
Each visibility check maps txid→CSN (needs a cache).
A "commit in progress" state must be handled.
PostgreSQL's multi-year CSN patch effort was never merged [mem],
showing it is subtle to retrofit. For a new engine, that matters
less.
Recommendation:CSN (option 2).
✎ My comment (D4.a):
D4.b — Default isolation
level
Engine
Default
PostgreSQL
READ COMMITTED
Oracle
READ COMMITTED
SQL Server
READ COMMITTED (locking unless RCSI) [mem]
MySQL InnoDB
REPEATABLE READ
CockroachDB
SERIALIZABLE (READ COMMITTED added later for app compatibility)
[mem]
Jepsen on MySQL 8.0.34 (Dec 2023) [src]: MySQL's
default REPEATABLE READ allows G2-item, G-single and lost updates, and
violates internal consistency and monotonic atomic view. Jepsen's
verdict is "somewhat stronger than Read Committed"; AWS RDS MySQL
clusters also routinely violated serializability. The lesson: a
stronger-sounding default that doesn't deliver is worse than an honest
weaker one.
PostgreSQL apps, ORMs and drivers assume READ COMMITTED semantics,
including re-checking rows after a lock wait.
Recommendation:READ COMMITTED by
default (PostgreSQL-compatible), plus a correct REPEATABLE READ
(snapshot isolation).
✎ My comment (D4.b):
D4.c — SERIALIZABLE at GA?
SSI (Serializable Snapshot Isolation) in
PostgreSQL, Ports & Grittner, VLDB 2012 [src]: under 7%
overhead relative to snapshot isolation in their benchmarks, and it
beats two-phase locking on read-heavy workloads.
But it is hard to get right. Jepsen found
G2-item serializability violations in PostgreSQL 12.3
(2020), nine years after SSI shipped in 9.1, under normal
operation. It was fixed after the report [src].
Options:
RefuseSERIALIZABLE with
0A000 until SSI ships (current plan).
Honest.
But some apps and ORMs set SERIALIZABLE (it's configurable in Django
and Prisma), and they'd break [mem].
Silently run snapshot isolation and call it
serializable.
This is what Jepsen criticised in multiple databases.
No.
Correct-but-coarse SERIALIZABLE at GA, SSI in 1.x.
At GA, serializable transactions take strict two-phase locks, with
shared locks on tables or ranges they read.
Always correct, but concurrency for SERIALIZABLE transactions is
low. Other isolation levels are unaffected.
Apps that request it keep working; performance improves later.
Full SSI at GA. Adds ~4–6 weeks and the risk of
subtle bugs late in the schedule.
Recommendation:3
(correct-but-coarse at GA, SSI in 1.x). It's never wrong, it never
breaks apps, and it never lies.
✎ My comment (D4.c):
D5. ADR-04 — Connection
and process model
Options
Option A — Process
per connection (PostgreSQL)
Pros: strong isolation (a crash kills one backend),
simple programming model.
Cons:
Heavy per-connection cost and context switches.
The ecosystem relies on PgBouncer.
PgBouncer's transaction pooling historically broke session features:
prepared statements (supported only since PgBouncer 1.21, 2023 [mem]),
SET, advisory locks, LISTEN.
Option
B — Thread per connection (current prototype; MySQL's default)
Pros: simple; blocking code is fine.
Cons:
10k connections means 10k threads: scheduler thrash and stack
memory.
Lock contention grows with thread count.
MySQL ships thread-pool plugins (Enterprise, Percona, MariaDB) to
fix exactly this [mem].
Option C
— Worker thread pool + multiplexed sessions (planned)
Who: MariaDB/Percona thread pool, SQL Server
schedulers [mem].
Pros:
Sessions are cheap structs, so 10k+ connections cost only a little
memory.
Concurrency is bounded at the core count, so there's no thrash.
No external pooler, and session features keep working.
Cons:
A worker blocked on a lock wait or I/O idles a core. This needs
stall detection plus temporary extra workers, which MariaDB does
[mem].
More complex scheduling and fairness.
Harder debugging (no one thread per client).
Option
D — Thread per core, fully async (Seastar/ScyllaDB style)
Pros: the highest theoretical throughput; no locks
within a core.
Cons:
Every code path must be non-blocking, which is incompatible with
straightforward B+tree latching.
Shared-nothing data partitioning is a poor fit for transactional
OLTP with cross-row transactions.
Enormous complexity in C.
Evidence
Our measurement [ours]: the prototype's idle RSS is
4.3 MB.
Freund (2020) [src]: PostgreSQL per-connection memory < 2 MiB
with huge pages. The real limiter was snapshot scalability, which D4.a
addresses.
Recommendation
C, introduced in M5. Keep thread-per-connection (B)
until then, since it's simple and fine for development.
✎ My comment:
D6. ADR-03 —
Torn-page protection and page size
A crash in the middle of an 8 KiB page write can leave half old and
half new data: a "torn page". Redo can't repair a page whose base image
is corrupt.
Options
Option A —
Full-page images in the WAL (PostgreSQL)
How: the first change to a page after each
checkpoint logs the whole page.
Pros: no extra data-file writes; recovery restores
pages from the WAL; works with any filesystem.
Cons:
WAL volume spikes right after every checkpoint, so frequent
checkpoints mean more WAL.
Compression of these page images helps [mem].
Option B — Doublewrite
buffer (InnoDB)
How: pages are written to a scratch area first,
then to their home location.
Pros: the WAL stays small.
Cons: data writes double. MySQL users routinely
disable it on ZFS or on hardware with atomic writes to win back
throughput [mem].
Option C — Rely on
device atomic writes
How: Linux 6.11+ RWF_ATOMIC with NVMe
atomic write units; AWS offers "torn write prevention" for 16 KiB on
some instance types [mem].
Pros: zero overhead.
Cons: only on capable hardware and kernels, so it
can't be the default.
Option D — 4 KiB pages
A single-sector write on 4Kn NVMe drives is atomic per the NVMe spec
[mem], so torn pages vanish for direct I/O on such drives.
Cons:
Not guaranteed on 512e drives or with buffered I/O.
Smaller pages mean deeper B+trees and smaller maximum inline
rows.
A (full-page images, compressed) by default, plus C
(auto-detected atomic writes skip the images) in 1.x. Keep 8 KiB
pages. A sequential, compressible WAL is cheaper than doubled
random data writes.
✎ My comment (torn-page strategy):
✎ My comment (page size 8 KiB vs 4 KiB vs 16 KiB):
D7. ADR-10
— One file per database vs files per table
Options
Option A — One file per
database (planned)
Who: SQLite, Firebird (.fdb), SQL
Server (.mdf).
Pros:
One file descriptor; one fsync at checkpoint instead of many.
Trivially copyable (embedded, branches, backup); no per-table file
limits.
Cons:
Space reclamation. The classic story is InnoDB's
shared ibdata1, which never shrank, even after
dropping huge tables. That is why MySQL made
innodb_file_per_table=ON the default in 5.6 [mem].
One file means a larger "blast radius" for filesystem-level
corruption.
Option B — One
file (or file set) per table/index
Who: PostgreSQL (1 GB segment files per relation),
InnoDB file-per-table.
Pros: DROP/TRUNCATE returns space instantly (delete
the file); per-table I/O visibility.
Cons:
Thousands of files and file descriptors.
Checkpoints must fsync many files.
Harder atomic copies; embedded mode is messier.
Option
C — One file per database plus Linux hole punching
How: freed extents get
fallocate(FALLOC_FL_PUNCH_HOLE), so disk space returns to
the OS immediately without moving data. Trailing free extents are
truncated, and an online compact handles the rest.
Pros: fixes the ibdata1 problem on
Linux (Tier 1) while keeping all of A's benefits.
Cons:
Sparse files: some copy tools expand holes unless they are
sparse-aware [mem].
Filesystem support varies; ext4 and xfs support it [mem].
How much do we invest up front in making the whole engine runnable
under a deterministic simulator, with simulated disk, network, clock and
thread scheduling?
Evidence
FoundationDB: the docs describe deterministic
simulation of an entire cluster in a single-threaded process,
with an estimated equivalent of about one trillion CPU-hours of
simulation [src].
It's widely repeated that Kyle Kingsbury declined to Jepsen-test
FoundationDB because its simulator already tested it harder. That comes
from a vendor blog (WarpStream), not Kingsbury himself;
unverified [src].
TigerBeetle is built around a simulator (VOPR)
[mem], and Jepsen published an analysis of TigerBeetle 0.16.11
[src].
Antithesis is a commercial service founded by
FoundationDB alumni. It provides deterministic simulation via a
deterministic hypervisor, without code changes [mem].
The caveat: FoundationDB and TigerBeetle are
single-threaded by design. Our engine is multi-threaded
with shared-memory latches. To run deterministically, every latch,
condition wait and thread spawn must go through the platform layer, so a
simulation build can swap in cooperative green threads.
Options
Option A — Full DST
from M1 (current plan)
How: all I/O, time, randomness, network
and synchronisation go through src/platform/. The
simulation build runs everything on one OS thread with a seeded
scheduler.
Pros:
Every bug becomes reproducible by seed.
It finds crash and concurrency bugs that real-world testing rarely
hits.
It's a strong public reliability story (F-15).
Cons:
~3–4 extra weeks up front.
A permanent design constraint: no raw pthread or atomics-based
spinning outside the platform layer.
Lock-free code, if any, is hard to simulate faithfully.
Option B — I/O fault
injection only
How: a simulated disk and clock, but real
threads.
Pros: ~1–2 weeks; catches the durability bugs (like
D-01) deterministically.
Cons: concurrency bugs stay non-deterministic, so
they need TSan, stress tests and Elle.
Option C — Option
B now, plus Antithesis later
Pros: cheap now; deterministic concurrency testing
without design constraints later.
Cons: a paid external dependency; less
control.
Option
D — Real crash loops and Jepsen-style testing only
Pros: cheapest.
Cons: this is what let D-01 and D-02 survive a
green CI.
Recommendation
A, staged:
In M1, route I/O, clock, randomness and synchronisation primitives
through the platform layer, and build the simulated disk first (option
B's value, immediately).
Add the cooperative scheduler next.
Routing the synchronisation primitives costs little if it's done from
day one; retrofitting it later is very expensive.
✎ My comment:
D9. ADR-09 — Collations
(text ordering)
Evidence
glibc 2.28 (2018) reordered many strings across
locales. Existing PostgreSQL indexes built with libc collations no
longer matched the new order, which meant wrong query results and index
corruption until reindexed [src: PG wiki, Crunchy Data, pgEdge].
PostgreSQL 17 added a built-in,
platform-independent collation provider (C and
C.UTF-8) so results don't depend on the OS [src]. Caveat
from CYBERTEC [src]: at that time it supported only binary-style
collations, not natural-language ones.
ICU gives linguistic collations, but its data
library is large: tens of MB [mem], which conflicts with a ≤ 15 MB
static binary.
Options
Option A —
Byte/codepoint order only (C / C.UTF-8)
Pros: fastest, stable forever, tiny.
Cons:
ORDER BY name isn't "dictionary" order: case, accents
and non-Latin scripts sort by codepoint.
No case-insensitive comparison without lower().
Option B — OS locales (libc)
Rejected: the glibc 2.28 corruption story
above.
Option C — Bundled ICU
Pros: full linguistic support for every
language.
Cons: binary size; ICU upgrades change sort order,
so indexes need versioning anyway (PostgreSQL tracks ICU versions for
this reason [mem]).
Option D — Built-in
collations (planned)
How: codepoint order (default) plus
unicode (root Unicode Collation Algorithm ordering from an
embedded table) plus unicode-ci (case/accent-insensitive),
each with a versioned table recorded on every index.
Pros: stable, small, enough for most apps.
Cons: no per-language tailoring at first (for
example German phonebook order or Arabic-specific rules); building and
maintaining tables from Unicode data is our work.
Recommendation
D, with per-language tailorings as a 1.x feature
driven by demand. It would help to know your target markets and
languages: if product catalogs in a specific language need dictionary
sorting at GA, that moves tailoring earlier.
✎ My comment (and target languages/markets if
relevant):
D10.
ADR-13 — Linux I/O stack: direct vs buffered I/O, io_uring
Direct I/O vs buffered I/O
Buffered I/O (PostgreSQL's traditional model) goes
through the OS page cache.
Pros:
The kernel cache grows and shrinks elastically with free memory,
which is great on tiny boxes.
OS readahead comes free.
Simpler code.
Cons:
Double caching (buffer pool plus page cache holding the same
pages).
Less predictable memory and latency.
fsync semantics after errors are tricky (the fsyncgate history
[mem]).
Direct I/O (O_DIRECT), the common
InnoDB recommendation [mem], bypasses the cache.
Pros: memory use equals the buffer pool exactly;
predictable; no double caching.
Cons:
We must do our own readahead and write pacing.
A small buffer pool means every miss goes to disk, with no elastic
OS cache to soften it.
Alignment constraints.
Linus Torvalds famously criticised the O_DIRECT
interface [mem].
PostgreSQL 18 added asynchronous I/O for reads:
sequential scans, bitmap heap scans, VACUUM. Its default method is a
worker-process pool, not io_uring. Direct I/O remains a
developer option [src]. Reported gains were 15–25% faster sequential
scans in one benchmark on NVMe RAID [src].
Key nuance for our "tiny" goal: on a 512 MB VPS,
buffered I/O with a small buffer pool may use memory better
than direct I/O, because the kernel shares cache with the rest of the
system.
Recommendation: make it
profile-driven:
server and container with large memory:
direct I/O and a large buffer pool.
tiny and dev: buffered I/O and a small
pool.
Auto-detection picks between them, the choice is always visible, and
either can be forced.
✎ My comment (direct vs buffered I/O):
io_uring
Google (June 2023): 60% of exploits submitted to
its kernel exploit reward program (kCTF VRP) used io_uring. Google
disabled io_uring on ChromeOS and on production
servers, restricted it on Android, and investigated disabling
it on GKE Autopilot [src].
Docker's default seccomp profile blocksio_uring_setup, io_uring_enter and
io_uring_register [src].
As noted above, PostgreSQL 18 defaults to worker-based asynchronous
I/O, not io_uring [src].
Recommendation: an I/O thread pool is the
default, first-class path, and io_uring is used automatically
when available and permitted. Never require it.
✎ My comment (io_uring):
D11. ADR-15 —
Release binary: static musl vs glibc
musl static:
Pros: one binary runs on any Linux; tiny; no glibc
version issues.
Cons: a slower malloc and slower
string/memcpy routines [mem]; DNS resolver differences [mem].
glibc dynamic:
Pros: fastest libc paths; distro-native.
Cons: a minimum glibc version is baked into the
build; not a single portable file.
Static glibc: possible, but NSS/dlopen
caveats (DNS, user lookup) make it fragile [mem].
Recommendation: ship both (as
planned). Keep malloc off hot paths with arenas and slabs,
so musl's weakness doesn't matter. The perf lab measures the gap.
✎ My comment:
D12. ADR-11 — Embedded
mode at GA or later?
Pros of shipping at GA:
A unique story: SQLite-easy start with PostgreSQL wire when you
grow, on the same file.
Good for tests and CI (an in-process database).
Cons:
A stable public C ABI becomes a long-term
promise.
Background threads inside a host process.
No signal handlers allowed in the core.
Memory budgeting is shared with the host app.
Exclusive file locking.
More release surface.
Middle path:architect for embedding from
day one (no globals, no signal handlers in the core, all state in the
database handle). Ship the public embedded API in 1.1, after
the server API settles.
Recommendation: the middle path. Move F-01 from GA
to 1.1, keeping the architectural rule from day one.
✎ My comment:
Quick
confirmations (low controversy — a yes/no is enough)
ID
Decision
My recommendation
Q1 (ADR-05)
Report server_version = 16.x to drivers
(version() shows MiniGres) so drivers enable modern
paths
Yes
Q2 (ADR-06)
Strict: no silent truncation or overflow; unquoted identifiers fold
to lowercase; 63-byte names; UTF-8 only
Yes
Q3 (ADR-14)
One portable x86_64 release binary that picks CPU-specific code at
runtime; ARCH_LEVEL builds optional
Yes
Q4 (ADR-16)
Automatic system tuning with named profiles
(tiny/container/server/embedded/dev)
and visible setting sources