Offline-first mobile architecture
An offline-first app reads and writes to a local database on the device, and synchronizes with the server in the background whenever a connection is available. The user interface never waits for the network to show data or accept input. Connectivity becomes an optimization rather than a requirement.
It matters most for people who work where connections are poor or intermittent: field inspectors, delivery drivers, health workers, sales teams, travelers. It also makes every app feel faster, because local reads are instant.
Diagram
Section titled “Diagram”- The UI reads from and writes to the local database immediately.
- Each local change is also recorded in a queue of pending changes.
- When online, the sync engine sends pending changes in order, with an ID so retries are safe.
- The server applies them, reports conflicts, and sends back changes made by others, which update the local database.
Design decisions
Section titled “Design decisions”What to keep on the device. Only what the user needs offline: their assignments for the week, not the whole database. Decide limits per data type, and how old data is evicted.
How writes reach the server. Queue each change as an operation with a unique ID, so a retry after a lost response isn’t applied twice (idempotency). Send them in order per record.
How conflicts are resolved. Two people (or one person on two devices) may change the same record offline. Options, from simplest to most capable:
| Strategy | How it works | Fits |
|---|---|---|
| Last write wins | The latest timestamp overwrites | Low-value fields; risky because device clocks are unreliable |
| Field-level merge | Changes to different fields both apply | Forms where people usually edit different fields |
| Server rules | The server decides, using business rules, and tells the app | Inventory, bookings, anything with limits |
| Ask the user | Show both versions and let a person choose | Documents and notes where intent matters |
| CRDTs | Data types that merge automatically and always converge | Collaborative editing, lists, counters |
Avoid hiding conflicts. If the server rejects or changes something the user did offline, tell them clearly.
What must be online. Some actions can’t be done safely offline: payments, booking the last seat, anything needing a real-time check. Show these as unavailable offline, or queue them as requests rather than completed actions.
Security. Data on a lost device must be protected: encrypt the local store, use the platform’s secure storage for tokens, and support remote wipe for sensitive apps.
- Works anywhere, and feels instant everywhere.
- Fewer failed actions on flaky connections.
- Lower server load for repeated reads.
- Synchronization and conflict handling are hard to get right and to test.
- Data on devices raises security and privacy questions.
- Schema changes must handle devices running old versions with unsynced data.
Common pitfalls
Section titled “Common pitfalls”- Treating offline as an error state added late, rather than designing for it.
- Relying on device timestamps for ordering and conflicts.
- Unbounded local data that fills devices and slows startup.
- No visibility of pending changes, so users don’t know their work hasn’t reached the server yet.
Related patterns
Section titled “Related patterns”- State management at scale
- Backend for frontend
- Idempotency
- Public-sector benefit systems, where field workers often work offline
Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.