React Native · Offline & sync
Making an app trustworthy on a bad connection, not just functional on a good one
Field and warehouse users kept losing edits whenever the network dropped mid-session. The fix wasn’t a retry wrapper around the API client — it was a local mutation queue with explicit revision tracking, so the app could keep working offline and tell the truth when two edits collided on reconnect.
Context
The app was used by field staff and warehouse operators on connections that ranged from solid Wi-Fi to a single bar of signal inside a concrete building. Screens let people edit records — notes, counts, statuses — that a teammate could also be editing elsewhere at roughly the same time. The existing approach treated every write as request/response: if the network wasn’t there when the user hit save, the edit either failed loudly or, worse, sat in a half-submitted state the UI didn’t account for.
Problem
Two problems were tangled together. The first was availability: users needed to keep working with no connection at all, not just tolerate a slow one. The second, harder problem was correctness once they reconnected: if a record changed on the server while a device was offline, naively replaying the device’s queued edit on top would silently discard whatever the other person had written. A sync layer that’s available but occasionally destroys someone’s work is worse than one that just refuses to work offline, because the failure is invisible until someone notices their change is gone.
Approach — queue locally, version explicitly, surface the conflict
- Write-through to a local store first. Every edit lands in on-device storage immediately and the screen reflects it right away, online or not — the UI never blocks on connectivity to accept input.
- Tag each mutation with the revision it was based on. Every record carries a server-assigned revision number; a queued mutation records the
baseRevit edited from, not just the new value, so the server can tell whether anything changed underneath it. - Coalesce the queue per record. Rapid edits to the same record collapse into one pending mutation carrying the latest value and the original
baseRev, instead of replaying every keystroke as a separate write when the connection returns. - Drain the queue strictly in order on reconnect. Mutations replay FIFO against the server; each one either fast-forwards cleanly (
baseRevstill matches) or is rejected as stale, so later mutations in the queue aren’t applied against a record left in an inconsistent state by an unresolved one ahead of them. - Treat a revision mismatch as a conflict, not an error. When the server's current revision has moved past a mutation's
baseRev, that mutation stops and the record is markedconflictinstead of being retried or dropped. - Resolve with a decision, not a heuristic. A conflicted record shows both versions and asks the user to keep theirs or take the server's; last-write-wins and three-way auto-merge were both considered and rejected for this app because the data was free-text and operational, where a wrong automatic merge is more dangerous than a short manual decision.
Illustrative outcome
Figures below are illustrative, from working through this pattern on a representative sync screen — not a specific client’s production metrics.
- Editing kept working with the connection fully off, with no error state and no lost input — the queue is the only thing that knows the device is offline.
- Conflicts went from a silent overwrite (undetectable until someone complained) to a visible, countable event with its own log entry and an explicit user decision.
- Per-record coalescing kept the queue small even through long offline sessions with repeated edits to the same handful of records, instead of growing one entry per keystroke.
What I took from it
Offline support isn’t really about the network being gone — it's about admitting that time passes differently for a device that's offline than for the server, and that the two will disagree about the current state of a record. A revision number per record turns that disagreement into something you can detect cheaply (one integer comparison) instead of something you discover from a support ticket. The expensive part was never the queueing; it was deciding, up front, which kinds of conflicts are safe to resolve automatically and which ones need a human, and building the UI for the second case before the first offline session ever happened in production.
The interactive demo below makes the mechanism visible: go offline, edit notes, let a simulated collaborator edit the same notes on the “server,” then reconnect and watch the queue drain and the conflict get surfaced instead of silently resolved.