Every account, every bookmark, every reading position, every paragraph of translated text, and every line of the AI spending ledger lives in a single file called jbook.db. There is no database server. Nothing to install, nothing to log into, nothing listening on a port. The application opens the file when it starts and keeps using it until it stops.
That sounds like a shortcut a prototype gets away with. It has held up through months of real use, and the reasons it works are more specific than "SQLite is good enough."
What actually sits in the file
The file holds 28 tables. Users and login sessions are there, along with the password-reset tokens and the OAuth bindings. Bookmarks, reading positions, and reader settings are there too — they used to live in Redis and were moved into SQLite in June 2026, which tells you something about the direction of travel: when a piece of state needed to survive restarts and be queried properly, it ended up in the file.
So did the money. Every model call writes a row to an AI usage ledger: who called, what for, which provider, how many tokens, how long it took. Quota counts live in their own tables, and the billing logic reads them back to decide whether a request is allowed. The translation store is in there as well, paragraph by paragraph, one row per paragraph per target language, so a translated chapter is a query, not a file to parse.
What is not in the file: the books themselves. Those stay on disk as EPUBs and PDFs, and the parsed reader cache and cover images sit beside the database in the same data directory. The split is deliberate. The database holds facts that need querying and transactions. Blobs that are read start to finish live as files, and the database keeps pointers to them.
One file, then, is not quite the whole story. It is one file plus two companions — the write-ahead log and a small shared-memory file — and a directory of covers and cached parses next to it. Copy the directory and you have copied the service's memory.
Why a file was the easy choice
Starting the service creates the database if it is missing and builds every table if it is not there yet. All of it runs inside a single transaction at startup, and if any of it fails, the service refuses to start. There is no separate provisioning step, no migration to run by hand before the first deploy, and no second service to keep alive on a small machine.
That mattered because the machine is small and the team is one person. A standalone database would have meant installing and babysitting another server for a product whose whole dataset, after months of use, is about six megabytes. The live database measured in November 2026 was 6.4 MB. At that size, the operational question is not how the database scales. It is whether it needs operating at all.
There is a second, quieter reason. Development happens on Windows, production on Linux, and the database file moves between them without conversion. The same file opens in both places. For a project that also ships to people who install it themselves, that is a real feature: a self-hosted user gets the whole data layer by having the file, not by running a database server they did not ask for.
One writer at a time
SQLite lets many readers in at once, but only one writer. That is the whole cost of the decision, and the code is shaped around it.
Each thread keeps its own connection, created on first use and held for the life of the worker. Reads do not block writes and writes do not block reads, because the file runs in write-ahead logging mode: new writes go to a separate log file, and readers keep seeing the last committed state. WAL changes what a reader has to do while a write is in flight: nothing.
The place where the single-writer rule bites is quota. Deducting from a monthly allowance has to be atomic: check the remaining balance and add the charge in the same breath, or two requests landing together will both pass and the user will be overcharged. The quota code does this by taking the write lock up front, before it even looks at the numbers, with a conditional update that only succeeds if the balance is still inside the limit. If the update touches zero rows, the limit was hit and the whole thing rolls back.
When two writers collide, the loser waits five seconds and then retries, up to three times. A lock conflict is treated as an ordinary, expected event — logged at debug level, retried, and only surfaced if it keeps failing. That is the shape of the cost: a small pile of retry logic that a database server would have absorbed silently.
There is one more habit buried in the code. The function that closes a connection exists, but nothing in the application calls it. Connections are opened per thread and simply never closed until the worker exits. With a file, a stale connection is harmless; nothing times out, nothing drops. That same habit would be a slow leak of dead connections against a server across the network, and it is the first thing that would have to change if the database ever moved.
The part nobody migrates
Schema changes have no machinery behind them. There is no migration runner and no version number stored in the file. Startup runs CREATE TABLE IF NOT EXISTS for all 28 tables, which means a new table appears on its own, but a new column added to an old table's definition reaches only a fresh database — the existing table never re-runs its creation statement. So far that has been fine, because new features have mostly meant new tables. It is a bill that comes due the first time an old table needs a new column, and then somebody has to write the first real migration by hand.
Backups have the same character. There is no backup job in the code. The backup is a file copy, and the write-ahead log sitting next to the database is part of what has to be copied. That is either a relief or a risk depending on how you look at it: nothing to configure, and nothing checking that anyone remembered to do it.
When the file stops being enough
The decision was never that SQLite is the right database forever. A switch was costed out in September 2026 and deliberately not built: the conclusion was that the code changes were small but the lock and transaction logic would need rewriting and re-proving, and that work could not be verified without a real second database to test against. So the switch stays a plan, not a half-built branch.
The honest triggers are three. If lock contention stops being a rare retry and starts showing up in the logs as a pattern. If the service ever needs more than one writer process, since a file cannot be written from two machines. Or if the dataset grows past the point where copying a directory stops being a sane backup strategy. None of those has happened. The database is six megabytes, the retries are quiet, and the whole service still fits in a directory you can copy.
Until one of those changes, the file stays. It has the fewest moving parts of any database we could run, and the parts it does have — one writer, a log file, a retry loop — are all visible in a single module you can read in an afternoon.
About the author
- Writing about ebook technology.
Comments
Join the discussionNo comments yet. Be the first to comment.