Most field apps are tested in an office with good Wi-Fi and fail in a plant basement, a steel-framed warehouse or a site two valleys from the nearest mast. The technician taps Save, a spinner turns, and twenty minutes of readings vanish with a timeout. After the second time, the clipboard comes back out and the app becomes something people fill in at the end of the shift from memory.
The fix is not a better error message. It is an architecture in which the network is never on the critical path of the work.
An offline-first app does not survive losing the network. It assumes it never had one, and treats every connection as a chance to catch up.
This article walks through how that architecture works, organised around the specific ways offline apps go wrong — because each failure maps to one mechanism, and an app that has all of the mechanisms is the one technicians stop noticing.
A Cache Is Not an Offline Mode
The common first attempt keeps the app online-first and adds a cache: read from the API, fall back to stored copies when the request fails, and queue a few writes. It demos well and breaks under real use, because every screen still has two code paths and the offline one is the one nobody tests.
Offline-first inverts the dependency. The interface reads from and writes to a database on the device, always. A separate sync engine moves changes between that database and the server whenever it can. The UI never waits on the network, so there is no offline path to forget.
| Online-first with a cache | Offline-first | |
|---|---|---|
| Where screens read | The API, falling back to cached copies | The local database, always |
| Where Save writes | The API, with a queue as a fallback | The local database plus an outbox, in one transaction |
| What a timeout means | An error the user must handle | Nothing the user sees; the sync engine retries |
| Hardest part | Keeping two code paths consistent | Sync, conflicts and migrations — done once, centrally |
On Flutter we put that local store on SQLite, usually through Drift: relational queries for asset hierarchies and checklists, typed migrations, reactive streams that redraw a screen when the sync engine changes a row, and encryption through SQLCipher. Key-value stores are fine for settings and miserable for a plant with ten thousand tagged assets. The framework reasoning behind Flutter for this kind of work is in our Flutter vs React Native comparison.
Offline-first is not free. It adds substantial work to the data layer, so it earns its place when work happens in places without signal and losing a record costs a revisit. If the job depends on live data — real-time stock availability, a price that changes by the minute — an online app with honest error handling is the better build.
Failure One: Two Devices Mint the Same Record
If the server assigns IDs, a record created offline has no identity until it syncs. The app invents a temporary ID, other records reference it, and then everything must be rewritten when the real ID arrives. Temporary-ID remapping is one of the most reliable sources of sync bugs there is.
The device should mint the permanent ID at the moment of capture. A UUID is unique without coordination; UUIDv7, defined in RFC 9562, is time-ordered as well, which keeps database indexes compact on both sides. The record has the same identity on the device, on the server and in every reference between them from the first second of its life.
Failure Two: The Save That Arrives Twice
Networks fail in the worst possible place: after the server committed the write, before the response reached the device. The device retries, and without protection the server now holds two identical inspections. The mechanism that prevents this is an outbox — a table of pending operations written in the same local transaction as the data itself.
CREATE TABLE outbox (
op_id TEXT PRIMARY KEY, -- UUID, doubles as the idempotency key
entity TEXT NOT NULL, -- 'inspection', 'reading', 'photo'
entity_id TEXT NOT NULL,
op_type TEXT NOT NULL, -- 'create', 'update', 'transition'
payload TEXT NOT NULL, -- JSON, including base_version for updates
schema_ver INTEGER NOT NULL, -- which app version wrote it
created_at TEXT NOT NULL,
attempts INTEGER NOT NULL DEFAULT 0,
state TEXT NOT NULL DEFAULT 'pending' -- pending | sent | rejected
);The sync worker drains it in order, and the server records every op_id it has applied. A retried operation is acknowledged without being applied again, so retrying becomes safe and the worker can retry aggressively.
- Order matters per entity. The create of an inspection must reach the server before its readings. Draining in creation order handles most cases; dependencies across entities need the parent's ID in the child's payload so the server can refuse and the worker can retry later.
- One bad operation must not block the queue. If the server rejects an operation as invalid, retrying forever stalls every record behind it. Mark it rejected, keep draining, and surface it to the user as something to resolve.
- Back off, but never give up silently. Exponential backoff for transient failures; a visible state for anything that has failed for hours.
Failure Three: Two Edits, One Truth
A supervisor corrects a work order on the web while the technician, offline, updates the same record. Both edits are legitimate. The question is what the system does when they meet, and the wrong default — whichever arrives last wins the whole record — silently discards somebody's work.
The most effective technique is to design conflicts out of the data model: a gauge reading is a new row rather than an update to a field, a photo or signature is an append, a status change is a transition event. Append-only data never conflicts, and in a well-modelled field app most of what technicians capture is append-only. What remains needs a policy chosen per entity:
| Strategy | How it resolves | Use it for | Where it hurts |
|---|---|---|---|
| Append-only | Both changes are kept; nothing to resolve | Readings, photos, notes, time entries | Requires modelling discipline up front |
| Per-field last writer wins | Edits to different fields merge; same field, the later one wins | Descriptive forms, contact details | A same-field collision still loses one value |
| Server decides | The server validates against current state and may reject | Status transitions, stock quantities, approvals | Rejections need a clear message on the device |
| Human resolves | Both versions are kept and flagged for review | High-value records where both edits matter | Someone must own the review queue |
Do not use device clocks to decide who wrote last. Phones drift, get set to the wrong time zone and are occasionally set wrong on purpose. Each server record carries a version number; an update from the device includes the version it was based on, and a mismatch means a conflict. The device's timestamp is still stored — as captured_at, a business fact about when the reading was taken, never as an ordering signal.
Failure Four: The Device That Knew Too Little
An offline app is only as useful as the data already on it. Syncing the whole database to every phone does not scale, and syncing too little means a technician arrives at a machine the app has never heard of. The download side needs as much design as the upload.
- Scope by assignment. The device holds the technician's jobs, the sites those jobs touch, the asset hierarchy beneath those sites, checklist templates and the parts they may need — and nothing else.
- Pull deltas, not snapshots. The device keeps a cursor and asks for changes since it. The cursor must grow in commit order. An
updated_attimestamp or a sequence assigned at insert does not, because transactions commit out of order and a slow one becomes visible behind a cursor that has already moved past it. Mature sync layers read the database's replication log or hold the cursor back behind the oldest in-flight transaction. - Deletes travel as tombstones. A record that disappears from the server must arrive on the device as an explicit removal — including records the user can no longer see because a job was reassigned.
- Pack before leaving. A full sync at the depot, with a visible "ready for offline" indicator and the time of the last complete sync, turns the morning Wi-Fi into a checklist item rather than a hope.
Failure Five: Photos That Never Leave the Phone
Photos are where offline apps quietly lose evidence. They are large, they fail mid-upload, and they compete with structured data for a weak connection. They need their own pipeline.
- Capture to the app's own storage, compressed and resized at capture time, with a content hash computed immediately. The record stores the hash and local path, not the image.
- Sync the record first. The server accepts an inspection whose evidence is still pending and shows it that way, so the office sees the work before the photos land.
- Upload in resumable chunks — S3 multipart uploads via pre-signed URLs, or the open tus protocol — so a dropped connection resumes from the last chunk rather than starting a 6 MB file again.
- Delete locally only after the server confirms the hash. An upload that returned success is not proof that the bytes arrived intact.
Failure Six: The Operating System Kills the Sync
Teams assume that once a connection returns, the app will sync in the background. Mobile operating systems disagree. Android's WorkManager runs deferred work with a network constraint but schedules it around battery and system load. iOS's BGTaskScheduler lets the system decide when, or whether, background work runs, and a user who swipes the app away stops it entirely.
So sync opportunistically and from several triggers: when the app comes to the foreground, when connectivity changes, after every save, on a manual "sync now", and in background tasks as a bonus rather than the plan. Also, do not trust the connectivity flag. Packages such as connectivity_plus report that an interface exists, not that the internet is reachable — plant Wi-Fi with no uplink and captive portals both look connected. Probe your own API's health endpoint before declaring the device online.
Failure Seven: Things That Expire While You Are Away
Two kinds of state age while a device is offline, and both strand captured work if nobody planned for them.
Sessions
Short-lived access tokens expire mid-shift. If a failed token refresh logs the user out, a day's work becomes inaccessible until the network returns. Define an offline grace period as policy, keep the local database usable within it, and bind the outbox to the user who wrote it so operations still sync under the right identity later. Because the device now holds real business data, encrypt the database, keep the key in the Keychain or Android Keystore, and support remote wipe on the next connection.
App versions
A technician installs an update while twenty operations are still in the outbox, written by the old schema. That is why each operation carries schema_ver: the server must accept operations from older clients for a defined window, and device-side migrations must run without touching pending operations. Forced upgrades are fine, but only after the outbox has drained.
Sync State the Technician Can Read
Hiding sync entirely sounds elegant and produces anxious users who re-enter work "just in case". The better pattern makes sync legible without making it the user's job:
- A per-record state: saved on this device, sent, confirmed, needs attention.
- One app-wide indicator with the time of the last successful sync and a count of pending items.
- A short list of rejected or conflicting items, each with a plain-language reason and a single action.
- No spinner that blocks capture — ever.
Rehearsing the Dead Zone at a Desk
Offline behaviour only gets tested if the conditions are reproducible. Before any field rollout, we run a set of scenarios on real devices, not simulators:
- Toggle airplane mode in the middle of a sync, then again in the middle of a photo upload.
- Force-quit the app with fifty operations pending and confirm none are lost or duplicated.
- Edit the same record on two devices and on the web, then reconnect them in different orders.
- Set the device clock a day wrong and confirm nothing orders by it.
- Stay offline for several days of realistic volume, then reconnect on a throttled network and measure how long the queue takes to drain.
- Install an app update with a full outbox.
The server side needs the matching tests: replay every operation twice and assert the database looks the same as after one pass.
Build the Sync Layer or Adopt One
Sync is the hardest part of this architecture, so it is worth asking whether to build it. Products such as PowerSync (syncing Postgres to SQLite on the device) and Couchbase Lite with its Sync Gateway provide the replication machinery. They win when the data model maps cleanly onto their rules and the team would rather not own a sync protocol.
Custom sync wins when conflict rules are domain-specific, when the server is an existing system with its own validation, or when the dependency risk matters: MongoDB's deprecation of Atlas Device Sync left teams that built on it migrating. Either way, the outbox, the ID strategy, the conflict policy per entity and the photo pipeline are decisions you still make yourself.
These patterns carry across the industrial plants and construction sites where signal is the exception, and they are the foundation of any field service management platform. If your crews are back on paper because the app cannot keep up, we can help you design the sync model before anything is built — talk to our mobile app development team through a build consult.
Frequently Asked Questions
What is the difference between offline-first and an offline mode?
An online-first app with a cache reads from the API and falls back to stored copies when a request fails, so every screen keeps two code paths and the offline one rarely gets tested. An offline-first app always reads from and writes to a database on the device, while a separate sync engine moves changes to the server whenever it can. The interface never waits on the network.
When is an offline-first field app worth the extra cost?
Offline-first adds substantial work to the data layer, so it earns its place when work happens in places without signal and losing a record costs a revisit: plant basements, steel-framed warehouses, remote sites. If the job depends on live data, such as real-time stock availability or a price that changes by the minute, an online app with honest error handling is the better build.
How do offline apps avoid duplicate records when they sync?
Two mechanisms do the work. The device mints a permanent ID, such as a UUIDv7, at the moment of capture, so there is no temporary-ID remapping. Each save also writes an operation to an outbox in the same local transaction, with an ID that doubles as the idempotency key. The server records every operation ID it has applied, so a retried operation is acknowledged without being applied twice.
How should an offline app resolve sync conflicts?
First, design conflicts out: readings, photos, notes and time entries become append-only records that never conflict. For the rest, choose a policy per entity: per-field last writer wins for descriptive forms, the server decides for status transitions and stock quantities, and a human resolves high-value records. Never use device clocks to decide who wrote last; compare a server version number and treat a mismatch as a conflict.
Can a mobile field app rely on background sync?
No. Android's WorkManager schedules deferred work around battery and system load, and iOS's BGTaskScheduler lets the system decide when, or whether, background work runs. Sync opportunistically instead: when the app comes to the foreground, when connectivity changes, after every save, on a manual sync, and in background tasks only as a bonus. Probe your own API's health endpoint rather than trusting the connectivity flag.
