Offline-first architecture

Local DB as source of truth, optimistic UI, write queues, and treating the network as an enhancement. Essential in India where connectivity is intermittent by default.

About 24 min read3-question knowledge check

The mental model

Offline-first inverts the default instinct of app development. Most apps treat the network as the source of truth and the local device as a cache: the screen asks the server, waits, and shows a spinner. Offline-first flips that — the local database is the source of truth, and the network is a background sync that enriches it. Every screen reads from and writes to the device; the server is something the device reconciles with later, on its own schedule.

The analogy that makes it click is Git. You do not edit files by talking to GitHub over the wire keystroke by keystroke. You have a full local repository; you commit locally, instantly, offline, as many times as you like; and separately you push and pull to reconcile with the remote. Your local repo is authoritative for your work until a sync happens. An offline-first app works the same way: the UI commits to the local DB immediately (a local commit), a background sync engine pushes and pulls (push/pull), and reconciliation handles the case where the remote moved too. The network being down is not an error state — it is just "no sync right now," exactly like coding on a plane.

The one idea that dissolves most confusion: **the render path and the sync path are different code paths that must never touch.** The UI renders *only* from the local DB and never awaits the network. The sync engine talks to the network and writes *only* to the local DB. If a screen ever awaits an HTTP call before it can paint, it is not offline-first — it is a networked app with a cache, and it will show a spinner the moment connectivity drops. This is especially non-negotiable in markets like India where intermittent connectivity is the default, not an edge case.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision