Most "offline support" implementations are caches. They store the last response and show it when the network is down. That works for reading. It fails for writing, because a write has to survive, in order, and reach the server later.
An offline-first app is a queue with a UI attached.
The shape that works
- The user action writes to local storage first.
- The same write is appended to a queue with a stable local id.
- The UI confirms immediately; it does not wait for the network.
- A sync worker drains the queue in order when connectivity returns.
- Each item is retried until it succeeds or is explicitly marked failed.
- The server treats the local id as an idempotency key, so a retry after a timeout does not create a duplicate.
The critical detail is step 1 happening before step 3. If the UI says "saved" and the write is only in memory, a crash loses it. If the write is on disk, the promise is true.
Ordering and duplicates are the hard parts
Two writes to the same record, made offline, must arrive in the order the user made them. A queue gives that for free if it is drained sequentially. Firing them in parallel does not.
Duplicates come from the network, not the user. A request can succeed on the server and still time out on the phone. Without an idempotency key, the retry writes the row twice. With one, the second attempt is a no-op that returns success.
What to test
- Airplane mode, create three records, force-quit, reopen, go online. All three should sync once, in order.
- Create a record, disable the network mid-request, then re-enable. The record should exist exactly once.
- Two devices editing the same record offline. Decide the conflict rule before shipping; last-write-wins is a choice, not a default.
- Kill the app during sync. On restart, the queue should resume without skipping an item.
If the app only tests the happy path, none of these are covered.
The app I built with this pattern
Daily Cash is an Android ledger built in Flutter with a write-ahead queue in front of Supabase. Entries are written locally first, replayed when connectivity returns, and exported to PDF and Excel on the device. The schema includes row-level security so each user's data is isolated in their own Supabase project.
Source is $15 with a commercial licence: https://takbirzaman.gumroad.com/l/daily-cash
The pattern is more important than the app: write first, queue the write, sync in order, make retries idempotent. Do that and "offline support" stops being a spinner with a warning.
Top comments (0)