Mobile Development

Offline-First: Building Mobile Apps That Stay Reliable When the Signal Is Weak

For apps used in the field, an internet connection cannot always be relied on. An offline-first approach keeps the app useful when the signal drops.

By Oemah Solution Editorial Updated 4 min read

This article was translated from Bahasa Indonesia with AI assistance and reviewed by our team.

A single cell tower in a rural area with a cloudy sky and a row of trees
Photo: Rural Dodgeville Cell Tower - panoramio by Corey Coyle · CC BY 3.0 · Wikimedia Commons

Many mobile apps are designed on the assumption that users are always connected to the internet. In the field, that assumption is often wrong: officers reporting from remote areas, sales staff travelling between cities, or residents in areas where the signal comes and goes. If every screen waits for a server response, the app becomes unusable exactly when it is needed most.

What is offline-first?

The Android architecture guide defines an offline-first app as one that is able to perform all, or a critical subset, of its core functionality without access to the internet. To meet that definition, the app must:

  • remain usable without a reliable connection;
  • display local data immediately, without waiting for the first network call to finish or fail;
  • fetch data with battery and data usage in mind — for example, only when charging or connected to Wi-Fi.

The minimum requirement: an offline-first app must still be able to read data without a network.

Architectural principles

The key lies in the data layer. Every repository that uses the network has at least two data sources: a local source and a network source. The local source — for example a Room database or files on the device — becomes the app's canonical source of truth. The UI layer only reads from local data; data from the server is used to update local data, not displayed directly.

With this pattern, a screen is populated immediately from the most recently stored data, then updated automatically as soon as new data arrives from the server.

Three strategies for writing data

The Android guide distinguishes three write strategies:

  1. Online-only. Data is saved only if it is successfully sent to the server. Suitable for transactions that must happen at that moment, such as fund transfers. Users need to be clearly told when they are offline.
  2. Queued writes. Data is placed in a queue and sent when the connection returns, with gradual retries (exponential backoff). Suitable for non-urgent data such as logs and analytics.
  3. Lazy writes. Data is first saved to the local database, then sent to the server as soon as possible. This is the right choice for important data that must not be lost — for example, a field report filled in without a signal.

On Android, the job of draining a queue like this is usually delegated to WorkManager, which keeps running even if the app is closed and can wait until the network is available.

Synchronisation and conflicts

When the app is back online, local data and server data need to be reconciled. There are two approaches:

  • Pull-based — the app fetches data when needed, for example when the user opens a particular screen. Simple, and suitable when offline periods are short.
  • Push-based — the app stores an adequate copy of the data from the start, then the server notifies it when something changes. The app can work offline for longer with minimal data usage, but the server must support synchronisation.

If the same data is changed in several places while offline, a conflict occurs. A common approach in mobile apps is last write wins: each change is given a timestamp, and the server keeps the most recent version.

Considerations for projects in Indonesia

For field reporting apps, public services or sales force apps, several decisions are best made from the outset:

  • Decide which functions must be usable offline and which may be online-only.
  • Store photos and attachments locally, send them when a connection is available, and show synchronisation status clearly to users.
  • Record the time and location when data is created on the device, not when the server receives it.
  • Test the app under poor network conditions, not only on office Wi-Fi.

Offline-first does add complexity to the data layer, but the result is an app that remains dependable in users' real-world conditions.

#mobile development#android#offline-first#architecture

Sources & references

This article is a summary and interpretation by the Oemah Solution team of the sources below. Refer to the original sources for full details and context.

  1. Build an offline-first app Android Developers · developer.android.com