AppStars

Offline-first is a promise, not a feature

Offline-first means people never lose work when the signal drops. How we build it: a cache of every read, an outbox for every write, entity tags and a careful reconcile.

"Works offline" is one of the most common lines in a mobile app brief. It usually sits in a list of features, somewhere between dark mode and push notifications.

It doesn't belong there. Offline-first isn't a screen you add. It is a promise to the person using the app: whatever you do, wherever you are, your work will not be lost. Every part of the app has to keep that promise, and the hard parts are the ones nobody sees.

These are our build notes on how we keep it, from field apps for line workers to native iOS and Android clients for a SaaS platform.

What "offline" actually means

The first mistake is trusting the phone. The operating system will happily tell you the device is online while it's connected to a hotel captive portal, a single bar of 4G at the edge of town, or a depot Wi-Fi that hasn't routed anything since lunch.

So we use a different definition: "offline" means our servers didn't answer. Not what the phone reports. If a request times out or fails, the app treats that moment as offline and carries on. That one rule removes a whole class of bugs where the app thinks it can save to the server, tries, and leaves the person staring at a spinner.

Reads: cache everything you show

If someone has seen a screen, they should be able to see it again in a dead zone. We keep a local cache of every read. When the network is there, the app revalidates in the background. When it isn't, the cached copy is what you get.

For field work you go further and download what people will need before they need it. In Field Portal, an iPad app for an electricity network's crews, that meant an offline asset map of a whole working area: poles, wires, premises and hazards. One working area synced 36,767 poles. Making that render smoothly offline took a custom spatial index and map clustering, but the principle is simple: the data is on the device before the truck leaves.

Writes: the outbox

Reads are the easy half. Writes are where promises get broken.

Every change a person makes goes into an outbox first, a durable queue on the device, and is synced to the server when the server answers. The screen updates straight away from local state. If the app is killed, the phone restarts or the battery dies, the outbox is still there when it comes back.

A few rules make any outbox trustworthy:

  • Write locally first, always. There's no separate "online" code path that skips the outbox. One path is easier to test and impossible to forget.
  • Keep the order. Create a record, then edit it, then attach a photo. Send them out of order and the server will reject the edit for a record it hasn't seen.
  • Make every operation safe to retry. A request can succeed on the server and still look like a failure on a flaky connection. The server must recognise a repeat and not apply it twice.
  • Never drop a failed item silently. If the server rejects something for good, show it to the person and let them decide.

Conflicts: entity tags

Offline work means two people can change the same thing without seeing each other's changes. You need a way to notice.

On the Knowby platform, every record carries a database-generated entity tag, a version marker that changes whenever the record does. Reads send the tag they already have, and the server answers "not modified" if nothing changed. Writes send the tag they were based on. If the record has moved on since, the server refuses the write instead of quietly overwriting someone else's work. That's optimistic concurrency, and it turns a silent data-loss bug into a decision the app can handle.

Reconcile: putting it back together

When the outbox drains and something comes back as a conflict, the app has to reconcile. This is the part worth sketching (simplified pseudo-code, not production code):

on server_reachable:
  for item in outbox.in_order():
    result = send(item.operation, if_match = item.base_tag)

    if result.ok:
      local.apply(result.record, tag = result.tag)
      outbox.remove(item)

    else if result.conflict:
      latest = fetch(item.record_id)
      merged = merge(latest, item.operation)
      if merged.is_clean:
        item.operation = merged
        item.base_tag = latest.tag
        continue                # retry on the next pass
      outbox.park(item)         # the person decides
      notify_user(item)

    else if result.unreachable:
      stop                      # offline again; keep everything

    else:
      outbox.park(item)         # rejected for good; never drop it
      notify_user(item)

The details of merge depend on the data. Some fields can safely take the latest value. Others, like a signed safety form, should never be merged automatically. The important part is that every path ends with the work either saved or in front of a person. None of them end with it gone.

Staying current once you're back

Correct is not the same as current. Once the device is online, people expect to see other people's changes without pulling to refresh. On the Knowby platform, changes stream to every client over Server-Sent Events within about a second.

The rule we built it around: correctness lives in the tag; the stream only makes it timely. The live stream is a hint that something changed. The entity tag is still what decides whether your copy is right. If the stream drops, nothing is wrong; the app just finds out a little later on the next revalidate.

Test the bad days on purpose

You can't test offline-first by turning on flight mode once before a release. The failures that hurt are the in-between ones: the request that reached the server but whose reply didn't come back, or the outage halfway through a sync.

For the Knowby mobile apps we ran end-to-end tests through a fault-injection proxy that simulates outages, so those in-between cases were tested automatically, not just when someone remembered.

A checklist for your next field app

  • Define offline as "our servers didn't answer", not what the phone reports.
  • Cache every read, and pre-load what people need before they head out.
  • Send every write through a durable, ordered outbox, with no shortcut path.
  • Make every server operation safe to retry.
  • Put a version tag on every record, and refuse writes based on a stale one.
  • Decide per field what can merge automatically, and what a person must decide.
  • Never drop work silently. Park it and tell someone.
  • Test the in-between failures automatically, on every change.

If your people work where the signal doesn't reach, our mobile and field apps page shows how we approach it, and the Field Portal case study shows it in the field.

Bring us the hard problem.

A 45-minute discovery call with the engineer who'll build it.