TL;DR. Offline-first is one model, not a feature. The local database is the source of truth (the one copy the app trusts). The screen reads only from it. Three choices change for each kind of data: how it is written (online-only, queued or lazy), how it syncs (pull, push or hybrid), and who wins a conflict. This page has a table of these choices and spoken outlines for three levels.
1. The model in plain words
In Google's Android guidance, offline-first means the app keeps working without a connection, either completely or for its most important features. The same guide says to show stored data at once, instead of waiting for a first request. It also says to think about battery and data use when the app fetches data.
The design starts in the data layer with two operations, reads and writes. Reads must work with no network at all. The guide wants every repository that touches the network to use two sources: one local and one remote.
- The local database is what everything above the repository reads. Treat it as the version of the truth that the screens trust, and let nothing else feed them. Room (Android's on-device database), DataStore or plain files can hold it.
- The server holds the real state. The local database catches up with it when it can.
- Screens and ViewModels never call the network. Only the repository does.
- Reads are reactive: the repository gives out observable types, which tell the screen when data changes. Writes go to the local database first, so the screen updates.
The Android data layer page says the same thing from the other side. Each repository defines a single source of truth. For offline-first, a local data source such as a database is the recommended one.
The page also sorts work by lifetime. There is UI-oriented work, app-oriented work, and business-oriented work. Business-oriented work cannot be canceled and should survive process death. WorkManager is the recommended tool.
The guide is for Android only. Apple has no page that defines "offline-first". What we can say from Apple's documentation is narrower. The Core Data overview says to use it to save permanent data for offline use, or to cache temporary data. The SwiftData overview says an app that fetches from a web service might use it for a light cache and limited offline use.
Mapping the Android model onto iOS is our synthesis. The case studies mark where iOS needs your own code.
2. The decision table
Every row is one operation from a case study. Read each row as a short answer to "what would you pick, and why".
A few terms in the table. An online-only write needs the network at that moment. A queued or lazy write is saved on the device first and sent later, from an outbox (a saved list of work the server has not yet confirmed). A cursor is a marker for where the last sync stopped. An idempotent request has the same result when done twice as when done once.
| Data or operation | Read strategy | Write strategy | Sync style | Conflict rule | Case study |
|---|---|---|---|---|---|
| Chat: send a message | Reactive read from the local database | Lazy write through a local outbox | Hybrid: socket and FCM hints trigger a pull by cursor | Server sequence (seq) is the authority; clientId dedupes | Chat app, sections 4, 5 and 8 |
| News feed: like a post | Cache first, then revalidate; paged from the database | Lazy write with an idempotent PUT or DELETE | Pull by opaque cursor, plus a "New posts" hint | Local intent wins until the server confirms | News feed, sections 4 to 6 |
| Photo upload | Upload state read from the database | Business-oriented queued or lazy work, resumable by block | Push-style upload, cloud changes pulled by cursor (hybrid) | Version check on commit; keep both on a conflict | Photo and file sync, sections 4, 6 and 7 |
| Booking: hold and pay | Saved trips read offline | Online-only write | Pull on demand; ask the server after any interruption | Server owns inventory, price and state; version ignores stale responses | Booking app, sections 2, 5 and 7 |
| Analytics events | Not read by the UI | Queued write | Drain the queue in batches | Server dedupes by event ID and batch ID | Analytics SDK, section 5 |
| Push token registration | Local registration record is the source of truth | Queued write by a unique job | Push of local state to the backend; inbox pulled by cursor | Upsert by installId; the local version counter shows what is uploaded | Push SDK, sections 3, 4 and 6 |
Three notes on the table:
- The Android guide says analytics events suit queued writes. It says a bank transfer suits online-only writes. Booking is in the second group for the same reason: a queued write could let a user "book" a room that no longer exists.
- The guide recommends lazy writes for data the app cannot afford to lose. It warns that they get tricky when the local and remote copies disagree after the connection returns. Chat, likes and photos are lazy writes for that reason. The conflict column is where the work is.
- Hybrid sync is the guide's term for pull and push together. Its example is a social feed that the app pulls on demand, plus push for data of the signed-in user. The news feed, chat and photo rows fit that shape.
3. What "offline" really means on a device
"No network" is the easy case. The harder cases are those where your code stops running, or the network is poor. This list shows only what the guides and Apple's pages say.
On Android:
- Process death. The app process (the running copy of the app) can be ended by the system. The data layer page says business-oriented work must survive process death, and it recommends WorkManager. A coroutine in
viewModelScopeis the wrong place for a send or an upload. The chat case study keeps the pending row in Room and the send in a unique worker for this reason. - Queues and monitors. The offline-first guide names two tools. Queues delay reads and writes until the connection returns. Network connectivity monitors give the signal to start the queue. WorkManager covers both as persistent work. It uses
NetworkType.CONNECTED, and backoff (wait longer after each failure) when the work returnsResult.retry(). - Conditions. The guide suggests syncing at good moments, for example while the phone charges or uses Wi-Fi. The photo case study turns that into constraints on the work request.
- Limits that change by version. Foreground service types and job quotas differ by Android version. The photo and chat case studies say to check them for your target SDK. We do the same.
On iOS:
- No equivalent to WorkManager. The chat case study says it plainly: you write your own outbox table and empty it on send, on foreground, when the network returns, and on push. This is our synthesis from Apple's APIs.
- Background transfers. Apple's
URLSessionpage says background sessions let uploads and downloads continue while the app is not running. ThewaitsForConnectivitypage says background sessions always wait for a connection. A foreground session fails at once when there is none. - Metered and constrained networks.
allowsConstrainedNetworkAccesscovers Low Data Mode. Apple advises limiting constrained access to tasks that the user starts, and delaying optional tasks. - Background processing. The
BGProcessingTaskpage says it runs only while the device is idle, and the system can interrupt it. - Force-quit. The photo and chat case studies record, from Apple's documentation, that a force-quit cancels background transfers. Nothing starts the app again until the user opens it.
- Connectivity monitoring. The abstract of
NWPathMonitorsays it observes network changes. Its page had no more text in the JSON we fetched, so we claim nothing more.
Storage pressure is a gap. We did not find a page that says how either system removes app data. So this page makes no claim about it. Set a limit on your own caches, as the news feed and analytics case studies do. Treat the removal question as an open item to research.
4. Conflict resolution and when last-write-wins is wrong
The guide says that conflict resolution often needs versioning. The app records when changes happened. It passes that data to the network data source, which is the final authority.
The common example is last write wins. Devices attach timestamps. The network discards data older than its current state and accepts newer data.
Last write wins is simple, but it is wrong in several places that the case studies cover:
- Anything with an order. Chat uses the server
seq, because device clocks drift.createdAtis used only to place pending messages at the bottom. - Anything with a base state. File sync commits with a
baseVersion. If the server is ahead, it answers409. The client then keeps a conflicted copy, so no edit is lost. Avoid a silent overwrite. - Anything with a pending local intent. In the feed, a refresh can overwrite a row that has a pending like. Then the like flips off and on. The fix is to keep the local intent until the server confirms the write.
- Anything that involves money. Booking avoids conflicts by refusing offline writes. The server decides, and the client only shows the state.
- Anything where timestamps are inputs. The guide lists a disadvantage of push sync: versioning for conflict resolution is nontrivial. Analytics sends two timestamps and lets the server correct for clock skew.
A simple guide: use last write wins only when losing the older write is acceptable and you can trust the clocks. You can also use it when the server assigns the order. Otherwise, use a sequence or a version that the server owns.
5. The five mistakes
- Optimistic UI with no reconciliation. The screen shows the new state at once. Nothing says what happens when the server disagrees, or when a refresh overwrites it. The news feed case study keeps a
pendingLikeflag and rolls back on a permanent failure. See News feed, section 5. - Retry without idempotency keys. A lost response plus a retry becomes a duplicate. Chat sends a
clientIdthat the server uses to find duplicates. Booking saves anIdempotency-Keybefore the first send. See Chat app, section 4, and Booking app, section 5. - Outboxes with no limit. A device may stay offline for weeks. An outbox that grows without limit becomes a storage and upload problem. The analytics SDK caps the outbox by count and bytes, drops the oldest events, and counts the drops. See Analytics SDK, section 5.
- Trusting device clocks. Booking computes the hold countdown from a duration that the server provides, on a monotonic clock (a clock that only moves forward). Chat orders by
seq. See Booking app, section 4. - Treating push as delivery. A push is only a hint. The chat and push case studies send a small hint and then sync by cursor, so a missed push is fixed by the next sync. Apple documents background pushes as low priority and not guaranteed. See Push SDK, section 6.
6. How to say this in an interview
Each outline below takes about 45 seconds to say (my estimate). Replace the example with the product in the question.
Mid level. "I would make the local database the source of truth, so the screen always reads from Room, or SwiftData on iOS, and shows data at once. The network layer writes into the database, and the screen updates from there.
"For writes, I would save locally first and send in the background with a retry. I would show a pending state. If the user is offline, I show saved data and a clear banner. I would also say what I do not handle yet, such as conflicts, and ask if the product needs them."
Senior. "I would split the feature by operation. Reads are reactive from the local database. For writes I pick one of three strategies. Payments are online-only. Events such as analytics are queued. User data that must not be lost, such as a sent message, is a lazy write.
"A lazy write needs a durable outbox. That is WorkManager on Android and my own outbox on iOS. Every request carries an idempotency key, so a retry is safe.
"Sync is a pull by cursor, with push as a hint. For conflicts I use a server sequence or a version, not device time. I would also name the failures: the app is killed, a response is lost, and a refresh overwrites a pending change."
Staff. "I would start by asking which data can be wrong, for how long, and who pays when it is. That fixes the write strategy and the conflict rule for each type of data. I would write the choices in one table that the teams share.
"Then I would cover the platform gap. Android has a persistent work framework and iOS does not. So I would state the weaker guarantee on iOS openly, and design recovery for app launch and foreground.
"I would also cover limits on the outbox and what to drop. I would cover versions of the schema and the wire format for old app versions. I would track metrics such as the age of pending writes and the duplicate rate. I would add a kill switch for sync, and a plan to split the design into modules that several teams can own."
7. Further reading
Fetched for this page:
- Build an offline-first app (Android)
- Data layer (Android)
- SwiftData (Apple)
- Core Data (Apple)
- BackgroundTasks (Apple)
- BGProcessingTask (Apple)
- URLSession (Apple)
- waitsForConnectivity (Apple)
- allowsConstrainedNetworkAccess (Apple)
- NWPathMonitor (Apple)
Parts of this page are changed versions of work created and shared by the Android Open Source Project. They are used under the terms of the Creative Commons 2.5 Attribution License. Original: Build an offline-first app.
Verification notes (last reviewed 14 Oct 2026)
Fetched and read (2026-10-13).
- Verified on 2026-10-13 by fetching the Android offline-first page and the data layer page.
- This covers the definition, the local and network data sources, reactive reads, the three write strategies, pull, push and hybrid sync, versioning and last write wins, queues and connectivity monitors, and work lifetimes.
- It also covers the Apple JSON for SwiftData, Core Data, BackgroundTasks, BGProcessingTask, URLSession, waitsForConnectivity, allowsConstrainedNetworkAccess and NWPathMonitor (abstract only; no discussion text came back).
- The Apple documentation links point to the human-readable pages; we fetched the JSON versions.
Not fetched again here.
- The table rows, the mistakes, the statements about force-quit and about no equivalent to WorkManager, and all case study details come from our own case study files and their own verification notes. They were not fetched again here.
My own opinion or design.
- Synthesis: the mapping of the Android model to iOS.
- Synthesis: the "pick last-write-wins only when" rule.
- Synthesis: the item on timestamps as inputs.
- Synthesis: the sync style in the photo and push token rows.
- Synthesis: the three spoken outlines.
Not verified.
- How either OS evicts app data under storage pressure (deliberately not claimed).
- NWPathMonitor behavior.
- How often BGTask runs.
- No iOS engineer has reviewed the iOS sections yet.
Changes by review pass.
- Edits on 2026-10-13 after the copyright audit: I rewrote section 1, two notes in section 2 and one bullet in section 3 in my own words. I read the Android offline-first page again to confirm the paraphrase (definition, two data sources, write strategies, fetching conditions). I checked developer.android.com/license (CC Attribution 2.5) for the attribution paragraph. No new factual claim was added.
- Source-check pass, 2026-10-14: I marked the 45 seconds per outline as my estimate.
Keep reading
Get the free one-page cheat sheet
One page: the five steps, a 45-minute time plan and two checklists. Print it or keep it on your phone.
We email you the cheat sheet after you confirm your address. You can also open it now from the Start here page. You also get a short email each week with a follow-up round, and a note when a new case is published. Unsubscribe any time. Privacy.