Offline-first & Data Synchronisation

Design apps that work without a network: local-first reads, queued writes, sync strategies and conflict resolution.

Advanced · about 10 hours · difficulty 4/5

Learn first: Local Storage: Key-value, SQLite & Files

Mobile users go through tunnels, lifts and bad coverage. An offline-first app reads from local storage first and syncs with the server when it can, so it always feels fast.

Core pattern

  1. The UI reads from the local database, never directly from the network.
  2. A sync layer fetches changes from the server and writes them locally; the UI updates reactively.
  3. User writes go to the local DB immediately and into an outbox queue, which is sent when online.

Decisions you must make

  • What must work offline? Often reading recent data and drafting; not everything needs it.
  • Sync strategy: pull with timestamps or cursors ("changes since X"), push the outbox, and handle partial failures idempotently (client-generated IDs help).
  • Conflicts: last-write-wins is simple but can lose data; field-level merges or asking the user suit collaborative data. CRDT-based tools solve harder cases.
  • Connectivity awareness: NetInfo, connectivity_plus or NWPathMonitor, but do not trust it fully; the real signal is whether requests succeed.

Tools

WatermelonDB, PowerSync, and Firestore's offline persistence for React Native; drift plus a custom sync in Flutter; Room with WorkManager on Android; SwiftData with background tasks on iOS.

Good enough to move on: your app lets users create items offline, shows them immediately, and syncs them without duplicates when back online.

Key concepts

  • Local-first reads
  • Outbox queue for writes
  • Pull sync with cursors
  • Idempotency and client IDs
  • Conflict resolution strategies
  • Connectivity detection
  • Sync engines and CRDTs

Mini project

Make your expense tracker offline-first: entries added in airplane mode appear instantly, sync when online, and never duplicate on retries.

Check yourself

Why do client-generated IDs make retrying a queued create request safe?

Free resources