MiniGres · Architecture

ADR discussion — decisions that need your call

12 decisions + 4 quick confirmations · updated 2026-11-25

Contents

Purpose: before M0/M1 code starts, settle the architecture decisions in PROD_PLAN.md that are expensive to reverse. Each section covers:

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:

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:

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)

Option B — PostgreSQL model: append-only heap, VACUUM, HOT

Option D — Heap table, in-place update, undo log; indexes point to a stable row id

Option E — LSM tree (log-structured merge)

Option F — Copy-on-write B+tree, no WAL

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

✎ 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

Options

Option A — Stay in C11 (current plan)

Option B — Rust (core and server), C ABI for embedding

Option C — Zig

Option D — Hybrid: C core + Rust for parsers, protocol and planner

Recommendation

There's no single "right" answer here; it depends on your team's Rust comfort.

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

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

Option B — Statement-level rollback by default, PostgreSQL mode opt-in (the current plan)

Option C — PostgreSQL semantics by default; statement-level rollback opt-in, plus cheap savepoints

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).

Option 2 — Commit sequence numbers (CSN; Oracle's SCN).

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]

Recommendation: READ COMMITTED by default (PostgreSQL-compatible), plus a correct REPEATABLE READ (snapshot isolation).

✎ My comment (D4.b):

D4.c — SERIALIZABLE at GA?

Options:

  1. Refuse SERIALIZABLE 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].
  2. Silently run snapshot isolation and call it serializable.
    • This is what Jepsen criticised in multiple databases.
    • No.
  3. 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.
  4. 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)

Option B — Thread per connection (current prototype; MySQL's default)

Option C — Worker thread pool + multiplexed sessions (planned)

Option D — Thread per core, fully async (Seastar/ScyllaDB style)

Evidence

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)

Option B — Doublewrite buffer (InnoDB)

Option C — Rely on device atomic writes

Option D — 4 KiB pages

Page size context

PostgreSQL uses 8 KiB, InnoDB 16 KiB, SQLite 4 KiB by default [mem].

Recommendation

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)

Option B — One file (or file set) per table/index

Option C — One file per database plus Linux hole punching

Recommendation

C.

✎ My comment:

D8. ADR-08 — Deterministic simulation testing (DST)

The question

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

Options

Option A — Full DST from M1 (current plan)

Option B — I/O fault injection only

Option C — Option B now, plus Antithesis later

Option D — Real crash loops and Jepsen-style testing only

Recommendation

A, staged:

  1. 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).
  2. 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

Options

Option A — Byte/codepoint order only (C / C.UTF-8)

Option B — OS locales (libc)

Option C — Bundled ICU

Option D — Built-in collations (planned)

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.

Direct I/O (O_DIRECT), the common InnoDB recommendation [mem], bypasses the cache.

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:

✎ My comment (direct vs buffered I/O):

io_uring

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

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?

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 Yes

✎ My comment (Q1–Q4):

Sources

Storage model (D1)

Language (D2)

Error semantics (D3)

Concurrency and connections (D4, D5)

Simulation testing (D8)

Collations (D9)

Linux I/O (D10)

↑