served

Articles ·

What happens to your writes when we pull the plug

Every change to Served has to survive the same routine: kill the server mid-write, start it again, and find every write it had confirmed. This is what that routine covers, and what it cannot.

A database host makes three promises, whether or not it writes them down. A write it has confirmed is not lost. One customer cannot reach another's data. What you put in is what you get out. Here is how each of those is checked before any change to Served is allowed out of the building.

A confirmed write is not lost

The test builds the real server, starts it, and has eight clients write to three databases as fast as they can. Each client remembers every write the API answered 200 to. Somewhere between 400 and 900 milliseconds in, the test kills the server with SIGKILL: no warning and no chance to finish anything.

Then it starts the server again on the same files and asks three questions of every database:

It does this three times in a row on the same data. A typical run confirms about nineteen thousand writes across the three kills and finds every one.

The reason this holds is not clever. Served asks SQLite to sync each commit to disk before it answers, and it answers only after SQLite says the commit is done. The test exists to notice the day a change breaks that order.

A download is one moment in time

A second test moves money. Ten rows start with 100 each. Four clients transfer random amounts between random rows, half as transactions sent in one request and half as BEGIN ... COMMIT. Meanwhile two clients download the database over and over, and two more run SELECT sum(balance).

The total is 1,000 before, after, and in every single download and every query in between. A download that caught one half of a transfer would show 990 or 1,010. In a typical two-second run that is around seven thousand transfers and four thousand downloads, each opened with a SQLite that is not the server's and checked.

One customer cannot reach another

There are only so many ways to name a file from SQL, and we keep a list of all the ones we know: ATTACH in a dozen spellings, VACUUM INTO, relative paths, URI filenames, paths hidden in parameters and sub-queries, extension loading, and a few stranger ones. A test plants a secret in a second account's database and then tries all of them from the first account. Every attempt must fail, no file may appear, and the secret must not come back in any result.

Another test does the same over HTTP with database names like ..%2F2%2Fprivate, and checks the files on disk before and after.

We also break the defence on purpose. With the rule that refuses ATTACH removed, the tests fail. With accounts made to share a folder, they fail. A test that passes when the thing it guards is gone is not guarding it.

A bad file cannot hurt the server

You can upload any bytes you like and call them a database. So each run takes a valid database, damages it four hundred different ways (flipped bytes, a mangled header, a missing tail, a page of noise) and uploads each one. About four in five are turned away at the door. The rest are accepted and then queried, written to, vacuumed and downloaded. Nothing has to work. The server just has to still be standing.

This runs with SQLite itself compiled under the address sanitizer, a tool that stops the program the moment any code reads or writes memory it should not. A fuzzer then keeps inventing new kinds of damage for as long as we let it.

What goes in comes out

A fuzzer generates integers, floats, text and blobs, stores them, and reads them back twice: once directly, and once through the JSON a client would see. Text that looks like a date stays text. A blob of zeros stays a blob of zeros. -0.0 keeps its sign.

The same idea covers whole databases. A test copies three databases to the off-site bucket, throws the disk away, rebuilds from the bucket alone, and compares every row. The API keys from before the loss still work.

The docs are run, not read

Every error code in the documentation is produced by a real request in a test, with the status the docs give. The examples in /llms.txt are sent to a real server and the responses compared with the text, character for character. If the docs and the server disagree, the build fails.

What this cannot show

Killing a process is not cutting the power. When the process dies, the operating system still holds what was written and gets it to disk. When the power dies, only what was already synced survives. We sync before confirming, which is what SQLite relies on, but no test here pulls a plug.

It also cannot show the absence of bugs in SQLite itself. SQLite is among the most heavily tested pieces of software there is, and we keep it current, but your SQL runs inside our process, and we say so.

All of this runs on the developer's machine before every push, in about a minute. A push that has not passed is refused.

Served is hosted SQLite. Real SQLite behind an HTTP API, $3 a month, and the file is yours to download whenever you like.

Read the docs