Offline-First Architecture Interview Questions
DATA › Offline
What does offline-first mean for a mobile app?
What a strong answer covers: The app reads from and writes to local storage as the source of truth, so it works without a network, and syncs with the server in the background when it can. The UI shows local data immediately rather than waiting on the network, and user actions are saved locally and sent later.
What does it mean for the local database to be the single source of truth?
What a strong answer covers: The UI only ever observes the database. Network responses are written to the database, never shown directly, and the database Flow updates the UI. This avoids the UI showing data that disagrees with what's stored, and means data is there after restarts and offline.
How do you handle writes made while offline, and sync them later?
What a strong answer covers: Save the change locally right away (optimistic update) and record it in a pending operations table or mark rows as dirty. A WorkManager job with a network constraint sends pending operations in order with idempotency keys, then marks them synced or handles failures. The UI can show which items aren't synced yet.
How do you resolve conflicts when the same data is changed on the device and on the server?
What a strong answer covers: Strategies: last write wins (by server timestamp, simple but loses data), server wins, client wins, field-level merge, version numbers or ETags so the server rejects stale updates and the client re-fetches and reapplies, or asking the user. For collaborative data, CRDTs. The right choice depends on the data: a profile name vs a shared document vs a counter.
Design offline support for a notes app used on several devices. Walk through the data model, sync protocol and edge cases.
What a strong answer covers: Each note has a client-generated id (UUID), updatedAt, a version, a dirty flag and a deleted tombstone. Local edits mark rows dirty; a sync worker pushes dirty rows with their base version, and the server rejects conflicts, prompting a merge. Pulling uses a changes-since cursor so you only fetch deltas. Edge cases: deletes must be tombstones so they sync, clock skew (use server versions), partial sync failure, first sync of a large account, schema migrations and logging out with unsynced changes.