All articles

Building Mobile Apps That Survive Real Networks

Your app works beautifully on office Wi-Fi. Then it meets a commuter train, a basement car park, and a prepaid data plan. Offline-first is not a feature — it is the baseline.

Every mobile app we have been asked to rescue had the same origin story. It was built and tested on a fast, stable office connection, it shipped, and then real users took it into lifts, tunnels, rural areas and crowded stadiums. The bug reports that follow are never 'the network is slow'. They are 'the app is broken', because from the user's side those are the same thing.

Treat the network as an optional dependency

The architectural decision that matters most is where your UI reads its data from. If a screen reads directly from an API call, it cannot render without connectivity — you are structurally guaranteed a spinner. If it reads from a local database that a sync layer keeps up to date, the network becomes an implementation detail of freshness rather than a prerequisite for function.

In practice that means a local store — SQLite, WatermelonDB, Realm, whatever suits the shape of your data — as the single source of truth for the interface, with writes queued as durable outbox records and drained when a connection appears.

The user tapped the button. That intent is real and should be persisted immediately, whether or not a server ever hears about it in the next thirty seconds.

Optimistic updates need a visible, honest state

Optimistic UI is standard advice and half-implemented almost everywhere. Teams apply the change locally and show it as though it were confirmed. When the sync later fails, the item silently disappears — or worse, silently stays.

Model three states explicitly and show them:

  • Pending — saved on device, not yet acknowledged by the server. Show it, subtly marked.
  • Confirmed — the server has it. Clear the marker.
  • Failed — the server rejected it. Surface it with a retry, and never drop it quietly.

A small clock icon next to an unsynced row costs an hour to build and eliminates an entire category of support ticket.

Idempotency keys, or duplicate orders

Retries are mandatory on mobile, and retries without idempotency keys produce duplicates. The classic version: a payment request times out client-side after the server has already processed it, the client retries, and the customer is charged twice.

Generate a UUID on the device when the user performs the action, send it with every attempt of that request, and have the server return the original result for a key it has already seen. This is a small amount of work on both sides and it removes an entire class of financial and data-integrity bug.

Test on conditions that actually occur

Airplane mode is the easy case — the app knows it is offline and can branch cleanly. The genuinely hard case is the captive portal, the connection that reports itself as online while dropping most packets, and the 8-second round trip. Those are where naive code hangs forever.

  • Use the network link conditioner on iOS and network throttling profiles on Android as part of QA, not as an afterthought.
  • Set aggressive, explicit timeouts. A request with no timeout is a hang waiting to happen.
  • Back off exponentially with jitter, so a recovering network is not hit by every client at once.
  • Verify that connectivity reporting is treated as a hint, not as truth — try the request anyway.

Resolve conflicts deliberately

Once devices can write offline, two of them will eventually edit the same record. Last-write-wins is a decision, not a default, and it is the wrong one for anything the user has invested effort in. Decide per entity: server-wins for reference data, last-write-wins for low-stakes preferences, and an explicit merge prompt for anything a person typed.

The short version

  • Render from a local store; let sync handle freshness.
  • Show pending, confirmed and failed states honestly.
  • Send idempotency keys with every mutating request.
  • Test degraded networks, not just the offline switch.
  • Choose a conflict policy per entity rather than globally.

Build for the tunnel and the office works automatically. Build for the office and the tunnel becomes a rewrite.