As asked
Design the data architecture for an offline-first mobile app that syncs with a server when connected. Cover conflict resolution and the user experience.
Sample answer outline
Local store (SQLite, Realm, WatermelonDB) as the source of truth for reads. Writes go to the local store first and queue for sync. Sync protocol: a sync log of operations or a CRDT, sent in batches with a server-assigned version. Conflict resolution: last-write-wins is simplest and sometimes wrong (for collaborative documents use a CRDT, for inventory use server-authoritative reconciliation). UX: show pending state on records that have not synced, give users a way to see and resolve conflicts, never silently overwrite. Discuss the cold-start sync for a new device and the partial-sync case.
Expect these follow-ups
- What if a user deletes a record offline while another user edits it online?
- How would you handle media (photos, video) in the same sync framework?
- When is offline-first too expensive to bother with?