s4ql

An SQL database for Go that stores everything in S3. Written by agents, trusted with simulation testing.

s4ql is an embedded database engine in the spirit of SQLite. Your Go application talks to the bucket directly, and there is no server to run. Every line of it is written by AI agents, and no human reviews the code. Trust has to come from verification.

  • Experiment
  • Storage built
  • First SQL built
  • Not ready for use

Why it exists

Two experiments in one repository. One is a database that needs nothing but object storage. The other is whether software that nobody reads can still be trusted.

Nothing to operate
Your Go application talks to S3 directly through the module. There is no server, no cluster, and no replica to look after. The bucket is the only infrastructure and the source of truth.
A database per user
Each database is a key prefix, so one bucket holds as many databases as you like. One database per user costs nothing extra, and write-heavy work spreads across them.
SQLite's SQL, strictly
s4ql speaks a strict subset of SQLite's SQL. Whatever it accepts behaves exactly as in SQLite. Everything else is rejected, never reinterpreted.
Trust without reading
AI agents write and own the code. Markus sets the goals and takes part in design and architecture; he does not review code. The bet is that a database can earn trust when its correctness is checked, not read.

What it does

A database in S3 is a log. Each commit is an immutable object named by the SHA-256 of its content and linked to its parent, as in git. One small file, manifest.json, points at the newest commit. Swapping that pointer is the commit.

manifest.json

{
  "version": 0,
  "branches": {
    "main": {
      "head": "d39febcf6aba…"
    }
  },
  "lease": {
    "holder": "5b0e3a4f9c1d77c3",
    "duration": "30s",
    "renewed": "2026-11-12T12:00:30.123Z",
    "salt": "c41d07a9e2b35f68"
  }
}

A compare-and-swap replaces this file. The transaction is committed when the swap succeeds, and not before.

  1. d39febcf6abaf7ee47aea6f615ae6e8be31d10f1c7ba4f3c8133917f63981295
    insert into t1 (v1) values (2);Parent b2116a98…
  2. b2116a9830d36bf1e6397287f9fab487243dd15484685c6e877f29376fb0e7da
    insert into t1 (v1) values (1);Parent 2f4e6858…
  3. 2f4e68582035cc5f8c0ab2f4d0e39d85a04e143979ac62ab3a2432493a12a1c7
    create table t1 (v1 int primary key) strict, without rowid;no parent

Illustration. Each bar code is the 256 bits of a real SHA-256, taken over sample content. A real commit object records the rows it changed, with the SQL kept beside them as a note.

Transactions
ACID within one database. No transaction spans databases.
Writes
One write transaction at a time per database. A second writer waits until the first has committed or rolled back.
Reads
In parallel, from a local SQLite cache, without contacting S3. Each read sees one consistent state, even while a write is in progress.
Cache
Holds the same tables and rows as the database, is never ahead of S3, and can be rebuilt from the log at any time.
Lease
One instance at a time holds the database's lease, recorded in the manifest. It lasts 30 seconds and is renewed every 20. A spare instance waits and takes over when the lease times out.
Unknown outcome
If the swap ends without an answer, the instance asks S3 until it knows. The transaction is committed if and only if its commit object is in the log.
S3 must offer
Strong consistency, compare-and-swap, and create-if-absent.
Interface
Go's database/sql.

How it is built

Agents write the code and nobody reviews it, so the tests have to show that it works. The production code runs unchanged inside a simulation where S3, time, and randomness are driven by one seed. The same seed always replays the same run, failures included.

Same seed, same field. Replay it and compare. Open the simulator
Deterministic simulation
S3, clocks, and randomness are reached only through interfaces. One seed controls a whole run, so any failure the simulation finds can be replayed exactly.
Buggify
Marked points in the production code do something legal but unusual in simulation: return an error, add a delay, take a rare branch. Each run switches on a different subset.
SQLite is the oracle
s4ql writes its own parser and engine, and checks them against SQLite. Results and errors are compared with SQLite's, and the parser is run on SQLite's own test statements.
Real S3
A conformance suite and integration tests run against a real S3-compatible bucket on Tigris, to check that the simulated store behaves like the real one.
Tests that test the tests
Property-based tests, fuzzing, and mutation testing. Bugs are planted on purpose to count how many seeds the simulation needs to find each one.
Everything written down
The spec, the research, the builders' diaries, and the conversations behind each decision are in the repository.

Status

As of 23 November 2026. s4ql is an experiment. It is not ready for use, and anything in it may change.

Works now

Through database/sql, with the package maragu.dev/s4ql as the driver:

  • create table and drop table of a strict table with one or more columns, exactly one of them the primary key, and a default with a literal on a column.
  • The column types int, integer, real, text, and blob. A value must have the exact type of its column.
  • Columns that are not null, and columns that take null.
  • insert of one row, with literals and arguments, with or without a list of columns. A column that the list leaves out gets its default.
  • select of named columns or *, with a where of comparisons and of is null and is not null, joined by and. A comparison may have its value on either side. Rows without order by come in a varying order.
  • order by of one or more columns, each ascending or descending, and limit with a number or ?, on select.
  • update and delete, with or without that where. An update may change the primary key, and RowsAffected is what SQLite reports.
  • returning at the end of an insert, an update, and a delete, with column names or *. Outside a transaction, the statement commits before it gives its first row.
  • create index and drop index, on one or more columns, each ascending or descending, not unique. The engine picks the index for a where by fixed rules.
  • if not exists on create table and create index, and if exists on drop table and drop index.
  • Arguments for a plain ?, directly and through prepared statements.
  • Transactions, also read-only ones.
  • Storage: a database is a log of commits in S3, with a local SQLite cache. One instance at a time holds a lease on it. Commits, recovery after a crash, and replay of the log work.
Checked

Against SQLite with generated statements, in the engine and through database/sql, in a deterministic simulation with planted bugs, and with mutation testing and fuzzing. The storage is also tested against a real S3-compatible bucket in CI.

Not built

or and other expressions in a where, offset, more than one row per insert, and a statement while rows of the same transaction are open.

Next

The rest of the SQL that glue needs, agreed one slice at a time (the roadmap's milestones). The slices, and how each is checked, are in the roadmap.

Roadmap

SQL grows in small slices. Nothing is supported until it is listed, all the way down to select 1, and each slice goes through every layer and is checked against SQLite before the next one starts.

  • Built
  • Agreed, not built
  • Open
  1. Storage core

    The log of commit objects, the manifest swap, the lease, crash recovery, and the local cache.

    Built
  2. S3 client

    Uploads are signed with the commit object's SHA-256, so the store refuses content that does not match it.

    Built
  3. Tokenizer

    The first piece of the SQL front end.

    Built
  4. Parser

    s4ql's own parser for all of SQLite's grammar. It agrees with SQLite on which statements parse, on the message of each syntax error, and on the shape of the syntax tree.

    Built
  5. The pass after the parser

    It rejects whatever the roadmap does not list, and it raises the errors that SQLite's grammar actions raise while they parse.

    Built
  6. Slice 1: one integer column

    create table, insert, select *, and drop table on a strict table with one int primary key. The answers must survive a restart with an empty cache.

    Built
  7. The driver

    A database/sql driver as the main interface.

    Built
  8. Slice 2: parameters

    A plain ? in the place of the integer literal of an insert, with a Go integer as the argument, directly and through a prepared statement. The number of arguments must equal the number of ?.

    Built
  9. Slice 3: transactions

    db.BeginTx begins a write transaction, which holds the place of the single writer until it commits or rolls back, or a read-only one with sql.TxOptions{ReadOnly: true}, which reads the state of its beginning and holds up no one. A transaction writes one commit object.

    Built
  10. Slice 4: the other types

    The column types int, integer, real, text, and blob, with their literals and Go arguments. A value must have the exact type of its column.

    Built
  11. Slice 5: several columns

    A table with several columns: one primary key, and the others not null. An insert gives the columns in the table's order or names them in any order, and a select names the columns it returns.

    Built
  12. Slice 6: null

    Columns that take null: the literal null, a nil argument, and a column left out of an insert. A null comes back as nil.

    Built
  13. Slice 7: where on select

    A column compared with a literal or a ?, is null, and is not null, joined with and.

    Built
  14. Slice 8: update and delete

    update ... set with literals, null, and ?, and delete from, each with or without the where of slice 7. RowsAffected gives the rows that SQLite reports as changed.

    Built
  15. Slice 9: indexes

    create index on one or more columns, each asc or desc, and drop index. The log holds only the definition, and the cache holds a real SQLite index. s4ql picks the index by fixed rules, so the choice is the same on every instance, and rows without order by come in an order that varies from query to query. The statements run, and generated queries run through every path that can serve them.

    Built
  16. Slice 10: if not exists and if exists

    create table if not exists does nothing when the table exists, and drop table if exists does nothing when it does not, and the same for indexes. A statement that does nothing writes nothing to the log. The statements run, and generated sequences check them against SQLite.

    Built
  17. Slice 11: default with a literal

    A column may carry default with a literal or null, and an insert that leaves the column out stores it. The commit format changes: a column carries its default. The statements run, and generated sequences check them against SQLite.

    Built
  18. Slice 12: a value on the left of a comparison

    In a where, a comparison may have a literal or ? on the left and the column on the right, such as ? >= timeout. The primary key and the indexes are used as for the other order, and the commit format stays as it is. The statements run, and generated sequences check them against SQLite.

    Built
  19. Slice 13: order by and limit

    select takes order by with one or more columns, each asc or desc, and limit with a number or ?. Where the engine sorts, rows that tie come in an order that varies from query to query. The commit format stays as it is. The statements run, and generated ordered and limited queries are compared with SQLite up to ties, the engine's choice is compared with a model of the rules, and a check shows that the order SQLite leaves unspecified varies.

    Built
  20. Slice 14: returning on insert, update, and delete

    An insert, an update, or a delete may end with returning and a list of columns or *. It gives one row for each row that it changes. Outside a transaction, the statement commits before it gives its first row. The commit format stays as it is. The statements run, and table tests compare them with SQLite, and through the driver with mattn/go-sqlite3, with goqite's send and its receive by id among them. Generated sequences with returning run in the engine's differential tests and in the driver's against mattn/go-sqlite3, and the simulation checks that the rows a caller read belong to a committed change and finds the planted bugs. Mutation testing of the new code left no mutant unexplained.

    Built
  21. More SQL, slice by slice

    Each slice is agreed before it is built. Every table is strict and without rowid, foreign keys are always enforced, and a name is never empty.

    Open
  22. Storage format version 1

    The formats are drafts until then. From version 1 on, every version of s4ql reads what any older version wrote.

    Open

Inspired by

s4ql builds on ideas from other databases and storage engines. How each idea works in its own project is written up in docs/inspiration.md.

SQLite
The embedded database s4ql is modelled on. s4ql speaks a subset of its SQL, checks its own answers against it, and uses it for the local cache.
FoundationDB
A distributed, transactional key-value store, tested in deterministic simulation. s4ql's simulation and its buggify points follow its example, and so does the rule that an application checks its own data after an unknown commit outcome.
Graft
A storage engine in Rust that replicates SQLite pages to object storage as an append-only log of commits, with no server in between.
SlateDB
An embedded key-value store in Rust that keeps all its files in object storage, with a manifest that lists the current state of the database.
Turbopuffer
A search service where object storage is the only source of truth and each namespace is a prefix in the bucket, with caches in memory and on disk in front of it.
Litestream
A tool in Go that replicates a SQLite database to object storage from its write-ahead log, and a SQLite plugin that queries the copy in object storage directly.

Follow along

The code, the spec, the open questions, and every conversation behind the decisions are public. Watch the repository to see whether a database written by agents can earn trust.

maragudk/s4ql on GitHub