> Fetch the index of every Tonbo docs page as Markdown at https://tonbo.dev/llms.txt

# Rules for databases

Last updated 29 October 2026

Check your program against these rules before you rely on it: each one keeps commits safe, one writer in charge, or the bill small.

Each rule links to its page, which shows what to write and what not to.

## Persist, then act

- [Await synced() before anything outside the process acts](https://tonbo.dev/docs/databases/rules/persist.md#synced)
- [Let gate() hold a handler’s answer](https://tonbo.dev/docs/databases/rules/persist.md#gate)
- [Record a side effect before you make it](https://tonbo.dev/docs/databases/rules/persist.md#side-effects)
- [Bound a wait where someone is waiting](https://tonbo.dev/docs/databases/rules/persist.md#bound)

## One writer

- [Run one instance per database](https://tonbo.dev/docs/databases/rules/one-writer.md#one-instance)
- [When a reset says stop, stop](https://tonbo.dev/docs/databases/rules/one-writer.md#stop)
- [Keep the cache directory, and never copy it](https://tonbo.dev/docs/databases/rules/one-writer.md#cache)

## Size and cost

- [Batch a step’s writes into one transaction](https://tonbo.dev/docs/databases/rules/cost.md#batch)
- [Write what changed, not the whole state](https://tonbo.dev/docs/databases/rules/cost.md#what-changed)
- [Keep each transaction under 128 MiB](https://tonbo.dev/docs/databases/rules/cost.md#transaction-size)

## SQLite

- [Leave the journal mode and the page size alone](https://tonbo.dev/docs/databases/rules/sqlite.md#pragmas)
- [Reach the data only through the connection open() returns](https://tonbo.dev/docs/databases/rules/sqlite.md#only-open)

## Setup

- [Create a database before you open it](https://tonbo.dev/docs/databases/rules/setup.md#create-first)
- [Give each program its own narrowed key](https://tonbo.dev/docs/databases/rules/setup.md#narrow-keys)
- [Create a database where its program runs](https://tonbo.dev/docs/databases/rules/setup.md#region)
- [Export a plain SQLite copy, never the cache directory](https://tonbo.dev/docs/databases/rules/setup.md#export)
