Launch offer: the first 1,000 users get Settl free for a year* Claim your spot
settlbuilding in public

The offline-first decision guide: when to use a library (always)

The short version

A hand-rolled system for keeping multiple devices in agreement produced weeks of bugs that could never be reproduced on demand: rows appearing on one device and not another, vanishing, returning, and two devices confidently disagreeing.

It was all deleted and replaced with an existing offline-first library. Keeping distributed copies of data in agreement is a solved problem with genuinely hard edge cases, and it is one of the few places where writing it yourself is almost always the wrong call.

Copy these prompts

Paste them into Claude Code (or any AI that can see your project), in this order. Each one answers a different question, and the first is usually the one that matters.

1. Ask what already exists before writing anything

My app needs data to stay in agreement across multiple devices, including offline. Before I write any of it, show me the established libraries for this in my stack and what each assumes about my data.

2. Ask what happens when somebody goes offline

Walk me through exactly what happens in my app when someone loses connection, keeps using it, and then comes back. Show me where changes are held and in what order they are sent.

3. Ask what happens when two people clash

Tell me what my app does when two people change the same thing at the same time on different devices. Show me who wins, whether anyone is told, and let me decide whether I actually like that answer.

The most expensive code I ever wrote is code I deleted. I hand-rolled offline sync (queue + cache + merge) and got weeks of "ghost bugs": rows appearing, vanishing, disagreeing across devices, none of it reproducible. I ripped the whole thing out for an offline-first library (Brick: SQLite + REST) in one brutal rewrite. It was the most satisfying diff of the project: the whole hand-rolled layer deleted, one data layer left standing.

The decision guide

Should you write your own sync engine? No. That's the guide.

Sync is a solved-by-libraries problem the same way crypto is: the failure modes are subtle, adversarial, and invisible in development. Here's what "queue + cache + merge" actually requires you to get right:

  1. Durable write queue: survives app kill, retries with backoff, replays in order, dedupes on retry (idempotency keys).
  2. Reconciliation: merging server truth into local state without erasing in-flight local writes (my vanishing-expense bug lived exactly here).
  3. Conflict policy: same row edited on two devices; last-write-wins, merge, or surface to user, chosen per field, not globally.
  4. ID strategy: client-minted IDs the server echoes back, so replays and merges reconcile by identity instead of guesswork.
  5. Failure taxonomy: a 400 (permanent, drop + tell user) is not a 500 (retry) is not a timeout (retry with caution: it may have committed).
  6. Reactivity: every local write must repaint every screen that renders derived state, or devices "disagree" with themselves.

Each item looks like a weekend. Together, interacting, they're the ghost-bug factory.

What to do instead

Steal this for your app

Run this on your codebase

Paste this into Claude Code in your repo:

Audit this repo for a hand-rolled sync engine hiding in plain sight.
Find the fragments: retry helpers, cache services, write queues, refresh-on-foreground hooks, and manual merge or reconcile code.
Count the sources of truth for user data (in-memory state, local DB, server overlay) and flag anything beyond one repository.
Check the write queue: does it survive app kill, retry with backoff, replay in order, and dedupe with idempotency keys?
Check reconciliation for paths that can erase in-flight local writes, and whether conflict policy is defined per field.
Check that 400, 500, and timeout failures are handled as three different cases.
Recommend whether an offline-first library (Brick, PowerSync, Replicache, RxDB, Electric) should replace the fragments.
Report findings as a checklist before changing anything.

Get the next one in your inbox