Guides

How to make your app work offline — step by step

Illustration: a stack of notes waiting at a closed barrier until it lifts

The classic beginner mistake about offline: "we just need to cache the data." Caching is maybe twenty percent of the job. The real pain starts where someone changed something without a network: ticked a checkbox, wrote a note, cancelled an order. Where did that go, and what happens when the network comes back?

Below is a working sequence. It isn't tied to a framework: this is how offline gets built on iOS, on Android and on the web.

1. Decide what must work without a network

Not the whole app. Take your list of screens and sort them into three groups: always works, read-only, honestly unavailable.

Notes, a to-do list, workout history — always. A recommendations feed — old data, read-only. Payment — unavailable, and that's fine: an honest banner beats a frozen spinner.

This step saves the most time. Half of the "offline features" turn out not to be needed.

2. Make the local database the source of truth

The key mental flip. Not "go to the network, and if that fails look in the cache," but the reverse: the screen always reads from the local database, and only from it. The network is what fills that database, not what the screen asks.

Android's official offline-first architecture guide states it as a rule: the local data source is the canonical source of truth for the app, and it should be the exclusive source of any data the higher layers read. The point is consistency — the screen looks the same in any network state.

In practice: you add a local database (SQLite and its wrappers, or built-in storage), and every server request ends by writing into it rather than returning data straight to the screen.

3. Make reads "live"

Since the screen reads from the database, it should update itself whenever the database changes. Then data arriving from the network just looks like a list refreshing, not a separate code path that reloads the screen.

Any modern data layer gives you the mechanics: subscribe to changes on a table. If you're building with an AI assistant, ask for exactly that: "the screen subscribes to changes in the local table, the network only writes to it."

4. Pick a write strategy

There are three honest options here, and mixing them up is the source of the murkiest bugs:

  1. Online only. Try to write to the server; on success update the local database, on failure show an error. Right for payments and anything you can't "promise."
  2. Queued. The change goes into a queue. When the network returns, the queue drains with growing pauses between attempts. Right for messages, likes, comments.
  3. Lazy writes. Write locally first (the person sees the result instantly), then queue the send to the server. This is what "the app feels instant" is made of.

For most user actions take the third. For money, the first.

5. Drain the queue properly

A queue isn't "let's retry in 5 seconds." Three things are mandatory:

  • Exponential backoff. Failed? Wait longer before the next attempt. Otherwise ten phones leaving a tunnel will storm your server at the same second.
  • A "network available" condition. The send job should wait for connectivity rather than waking up for nothing — as with a background task, where the conditions aren't yours to set, they're the system's.
  • Repeatability. A send can happen twice: the phone sent it and lost the network before the reply. Give every operation its own identifier and have the server drop duplicates — otherwise you'll collect two identical orders.

6. Decide what happens on conflict

Two people changed the same thing (or one person on two devices). The simplest workable strategy is last write wins: the device attaches a timestamp to the data, and the server discards anything older than its current state.

It has an honest downside: somebody's edit disappears silently. That's why text and lists often go further — merging per field ("name from the phone, phone number from the laptop") or keeping both versions. This is a cousin of a race condition, just stretched over days.

Pick your strategy up front and write it down in two lines. A silent "whatever happens" is the worst option.

7. Show people what's going on

Offline without indication feels like breakage. Minimum three states: "saved on device," "sending," "failed — will retry." Plus a global banner: "no network, changes are saved."

What you get

The app opens instantly — on a plane and in a lift. Changes don't vanish: someone ticks a box on the subway, rides up the escalator, and it all flies off by itself. The "loading" spinner on the first screen is gone, because the data is already right there.

Do I need my own server API for this?

Not necessarily. Ready-made backends (Supabase, Firebase and friends) ship sync out of the box, and some steps collapse into configuration. But steps 1, 4 and 6 are product decisions — nobody will make them for you.

How is this different from plain caching?

A cache speeds up reads and may be thrown away at any moment. Offline storage holds data you must not lose, including changes that haven't been sent yet. The difference is whether wiping it is harmless: for a cache, yes; for a write queue, no.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →