Food pantries run in church basements with poor Wi-Fi. If the check-in kiosk stalls when the connection drops, the volunteers go back to the clipboard. So registering, confirming the yearly form, checking in and looking someone up all had to succeed with no network, in under a second. Nothing done offline could be lost or applied twice.
The kiosk for FoodForms also had to serve many pantries run by volunteers with no IT staff. A deployment for each pantry does not scale to that. A shared database that relies on the application to filter each query fails the first time a query forgets its filter.
I met both requirements with six rules. Each one is here with the failure it prevents.

1. Screens never call the network
The kiosk and the staff screens are one installable web app. Every screen reads and writes a local IndexedDB store, which is the browser’s built-in database, and nothing else. The rule is about files. A short named list of modules may make requests: the sync engine, the desk-bound admin console and sign-in. No other file fetches.
This prevents a new screen that works on the developer’s desk and stalls in the basement. Nobody has to ask whether a new screen works offline, because it has no way to do anything else.
2. Every write is a local record plus an outbox entry
An outbox is a list of changes waiting to be sent. Each change is made by one function that, in a single local transaction, writes the record and appends an outbox entry. The screen sees the change immediately. If the device is offline, the entry waits.
This prevents both a lost change and a doubled one. The record and its entry are written together, so one cannot exist without the other. The entry’s id is generated on the device and doubles as the server’s idempotency key, which is an id the server uses to recognize an operation it has already applied. Replaying an operation is always safe.
The server answers each operation applied, duplicate or rejected. The first two clear the entry. A rejection is kept with its reason for staff to see, and is not retried forever.
- Writtenrecord and entry, one transaction
- Pendingwaits while the device is offline
- Pushedin order, with its idempotency key
- Clearedserver said applied or duplicate
- Rejected kept with its reason for staff
3. One sync engine does all the talking
The engine pushes pending operations in order, then pulls everything for the pantry that changed since its stored cursor. The cursor is a sequence number stamped by a database trigger on every synced table. A changed name, a merge and a deletion all arrive through the same path, so no kind of change needs sync code of its own.
Diagram as text
- Screen to Local store: write record
- Local store to Outbox: append entry, same transaction
- Local store to Screen: change visible immediately
- Outbox to Sync engine: pending operations, in order
- Sync engine to Server: push with idempotency key
- Server to Sync engine: applied, duplicate or rejected
- Sync engine to Server: pull changes since cursor
- Sync engine to Local store: apply pulled changes
The engine is pure TypeScript with its transport and its store passed in. That turns the awkward cases into ordinary unit tests: a failure in the middle of a batch, a replay, a rejected operation. Transport errors back off exponentially, up to five minutes, and a “Sync now” tap ignores the backoff.
A sync indicator is on every screen. Staff can open a view of exactly what has not synced and why, so a tablet that is behind does not go unnoticed.
4. Conflicts are decided in advance
Two tablets at one pantry can both work offline. The rules for what happens next are simple and written down. A household can have one visit per day, so duplicates collapse. Edits to a household are last-write-wins by row. A merge moves visits and forms to the surviving household. Live updates between tablets were an explicit non-goal.
This prevents a conflict from being settled differently each time, by whichever code happened to run.
5. The database isolates pantries
Each pantry is a subdomain. A request’s tenant, meaning the pantry it belongs to, comes from the authenticated device or user and never from the request body. Every tenant query runs inside a helper that sets the tenant for that transaction. Postgres row-level security policies on every tenant table do the isolation: the database itself refuses to return another pantry’s rows.
This prevents the query that forgets its filter. The application connects as a non-superuser role, because row-level security does not apply to superusers, and migrations use a separate owner connection. Every database test file asserts that a second tenant cannot see the first tenant’s rows. Adding a pantry is a new row and needs no new infrastructure.
6. A tablet is enrolled, and can be un-enrolled
A tablet holding a pantry’s roster is holding personal data. A tablet enrolls with a one-time token, delivered as a QR code in the console, an emailed link or a typed code. The token travels in the URL fragment, the part after the #, so it never reaches a server log.
This prevents a tablet that has left the pantry from keeping the roster. A revoked tablet’s next sync fails, and the app wipes its local database and returns to the enrollment screen.
What the rules cost
The local store has no application-level encryption. Tablets are expected to be device-managed with disk encryption. I documented this as an accepted risk, because the alternative was key management that volunteers would have to operate.
Last-write-wins loses the occasional concurrent edit. A household’s name and size are edited rarely, by people in the same room, so I did not build more than that.
Rolling out a format change is slower. A tablet reads check-in codes by itself, so every reader has to understand a new format before any writer produces it. I gated one such change on every enrolled tablet having been seen on the new build.
One piece of work came from the neighbors’ phones and not from the rules. Many neighbors use a cheap Android phone on a prepaid plan. I measured the phone site’s first load in production: about 700 KB uncompressed, with the kiosk’s and console’s code fetched behind it. I compressed the build, gave each app only its own code and its own slice of the translations, and set 320 px wide as the floor the test suites run at.
Where the rules were reused
The ticket printer checks neighbors in offline with the same idempotent outbox, kept on a microSD card. The “Mission Control” portal is an earlier offline-capable web app of mine with a visible sync status, and Architecture Patterns covers local-first design and tenancy more generally.
Scott Tompkins