State, data and offline · senior
Offline-first: outbox, sync and conflicts
An offline-first app reads from a local database, records every change in an outbox with an idempotency key in the same transaction, syncs when the network and the OS allow (with backoff), pulls server changes with a cursor, and resolves conflicts with server versions, never with device clocks.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- The local DB (SQLite) is what the UI reads. A user change writes the row and an outbox entry in one transaction.
- Each outbox entry has a client-generated id used as an idempotency key, so a retry after a timeout does not create a duplicate on the server.
- Sync triggers: app start, return to foreground, NetInfo back online, and opportunistic background tasks. Use exponential backoff with jitter; permanent errors move to a "failed" state the UI shows.
- Pull: delta sync with a server cursor; deletes arrive as tombstones.
- Conflicts: compare server version numbers and choose per entity: last-write-wins, field-level merge, or ask the user. Never order edits by device time; clocks can be wrong.
- NetInfo isConnected does not mean your server is reachable (captive portals, dead networks). Treat request failures as the real signal.
- Show sync status per record (pending, synced, failed) and give users a retry.
The red pen
Common traps: mistake → fix
Mistake: "Just retry the API call"
Fix: without an idempotency key a retry can create duplicates.
Mistake: "Use the device timestamp to pick the latest edit"
Fix: device clocks drift or are changed; use server versions.
Mistake: "isConnected means online"
Fix: it only means a network interface is up.
Easy to hard
Questions interviewers ask, easy to hard
- Field agents edit visit reports offline for days. Design the client data layer.
- Two devices edit the same record offline. Who wins?
- The app is killed mid-sync after the server applied 30 of 50 mutations. What state are you in?
- Build a hook that queues actions while offline and syncs when connectivity returns.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.