Skip to content
Lab
Engineering noteShipped

Offline-first is mostly about conflicts

Caching is the easy part. Notes on field-level patches, stale-write refusal and private data when two phones edit the same book offline.

Making an app open offline takes an afternoon. Making two devices that were both offline agree afterwards takes the rest of the project.

Patch fields, not documents

Sending whole documents means the last writer silently erases the other person's change. Sending field-level patches shrinks the collision surface to the fields both people actually touched.

Refuse stale writes on the server

Every document carries an updated-at stamp. Security rules refuse any update stamped earlier than the stored copy. When the app sees a refusal it fetches the server copy to decide whether this is a real conflict — the other phone changed or deleted this — or an ordinary error, and shows one notice per burst instead of a wall of errors.

Privacy is a query shape

Rules that hide private notes from the other user can't be satisfied by one broad query, so the app reads shared notes and the reader's own private notes separately and merges them. The server, not the UI, enforces privacy.

Idempotent background work

Recurring bills post automatically. Using transactions to create-if-absent means two devices waking up at once still post each bill exactly once.

Keep reading