Lorixen.
EN

Offline mobile apps: handling edits that clash on sync

Short answer: If your mobile app lets people work without a signal, such as technicians filling in job sheets in basements, drivers marking deliveries or sales reps editing orders on the road, two devices will sometimes change the same record before either has synced. You need a deliberate rule for what happens then. Decide per type of data: some can safely use "last write wins", some should merge field by field, and some, like stock or money, should only change online or through the server's own rules. Show users when something they changed was overridden.

Why offline apps get conflicts

An offline-capable app keeps a local copy of data on the device and syncs with the server when it can. Android's guide to building offline-first apps makes the local database the canonical source of truth for the app: the screens read from it, and a sync process exchanges changes with the network.

Conflicts appear when the same record is changed in two places between syncs. A field technician updates a job's notes in a plant room with no reception. Meanwhile, the office changes the job's appointment time. When the technician's phone reconnects, both changes arrive at the server. Which one wins, and does the other disappear?

If nobody chose a rule, the answer is usually whichever happened to arrive last, and someone's work quietly vanishes.

First decide how each write should behave

Android's guide describes three write strategies, and choosing between them is the first step:

  • Online-only writes. The write goes straight to the server and fails if there is no connection. The guide gives a bank transfer as the kind of near-real-time transaction this suits, and notes you may need to tell users the write failed or prevent them attempting it offline.
  • Queued writes. The change goes into a queue, which is drained with exponential backoff when the app is back online; on Android, the guide says this persistent work is often delegated to WorkManager. It suits things that are not time-sensitive, such as analytics events and logs.
  • Lazy writes. The change is written locally first, then queued to the server at the earliest opportunity. The guide notes this is nontrivial because conflicts can arise between local and network data when the app reconnects.

Most business data that users edit offline falls into the third group, and that is where conflict rules matter.

Strategy one: last write wins

The guide calls "last write wins" a common approach for mobile apps. Devices attach timestamps to the data they write, and the server discards anything older than its current state while accepting newer changes.

It is simple and often fine for data where only the latest value matters, such as a user's own preferences or a status field updated by one person. Its weaknesses are worth knowing:

  • Device clocks can be wrong, so "later" is not always later. Prefer server-assigned versions or record when the edit happened on a trusted clock where you can.
  • A whole-record overwrite throws away changes to other fields. Apply last write wins per field, not per record.

Strategy two: merge by field

If the technician changed notes and the office changed the time, there is no real conflict: both changes can be kept. Track which fields each device changed since its last sync and apply only those. Only when the same field changed on both sides do you need a tie-breaker.

For text-heavy fields such as notes, consider appending rather than replacing, so both contributions survive with who wrote them.

Strategy three: let the server decide

Some data should never be resolved by timestamps on phones:

  • Stock and quantities. Two reps each "reserving" the last item offline cannot both succeed. Send intentions such as "reserve one", let the server apply them in order and report back.
  • Money and prices. Payments, refunds and discounts belong in online-only flows.
  • Status transitions. A job cannot go from "cancelled" back to "in progress" just because a device was offline. Validate transitions on the server.

When the server rejects a queued change, the app must tell the user clearly and show the current state.

Show conflicts to users

Silent resolution is where trust breaks. Good offline apps:

  • Mark records with unsynced changes, for example with a small icon.
  • Show a clear message when a change was overridden or rejected: "The office changed the appointment to 2pm; your note was saved."
  • Keep a history so a supervisor can see what happened.
  • Offer a manual choice for the rare true conflicts that matter.

Deletions and long offline periods

Deleting a record on one device while another edits it offline is a classic trap. Rather than removing rows immediately, mark them deleted and keep the marker long enough for all devices to sync. Decide whether an edit should revive a deleted record or be discarded, and tell the user either way.

Also set a limit on how long a device can stay offline before it must refresh fully, so very old changes are reviewed rather than blindly applied.

Build or buy

Android's guide notes two broad approaches: a custom synchronisation stack, which gives maximum control over schemas and conflict resolution, or managed cloud services, whose SDKs handle caching, offline write queuing and bidirectional sync for you. Managed options are faster to start with, but read their rules closely. Cloud Firestore's offline documentation, for example, says that when the device comes back online it synchronises local changes, and for multiple changes to the same document it's last write wins. If that does not suit a record type, you still need to design around it.

A worked example

Picture a hypothetical Kilkenny lift-maintenance firm whose engineers record inspections offline in lift shafts. Office staff edited the same jobs to reschedule visits, and engineers' notes were sometimes lost when an older office copy synced last.

The developers switched to field-level merging with server-assigned versions, made notes append-only with author and time, moved parts ordering to an online-only action that queues a clear "will send when online" request, and added a banner when another person's change took precedence. Lost notes stopped, and parts orders no longer doubled up when two engineers ordered the same item offline.

FAQ

Is last write wins ever good enough?

Yes, for data owned by one person or where only the latest value matters. It is risky for shared records.

How do I test sync conflicts?

Use two devices or emulators, put both in airplane mode, edit the same record differently, then reconnect them in different orders.

Do web apps have the same problem?

Yes, if they work offline. The same rules apply.

If your field team's offline changes sometimes disappear or clash with the office, tell us how your app syncs today.

Sources

WhatsAppBook a call