Offline-first and sync

How do apps work without internet?

Apps work without internet, including with no Wi-Fi and no mobile data or load, by keeping the data and logic they need on the device. They read and write a local database, queue the changes that must reach a server, and sync when a connection returns. Some can also exchange data directly with nearby devices over Bluetooth or a local network.

TL;DR

Working without internet comes from the design, not a later add-on. The app reads and writes a local database, queues changes in an outbox with stable identifiers, merges with other copies when it reconnects, and can share data with nearby devices. Decisions that need one central authority, such as payments or unique bookings, should wait for a connection.

Learning objectives

After reading this article you will be able to:

  • Explain why thin-client apps fail when the network drops
  • Describe how a local database and an outbox keep an app working offline
  • List the design habits that make offline support easier to build

Network-dependent apps when the connection drops

When the connection drops, a thin-client app shows a spinner, then an error, and anything typed into a form may be lost. Many apps are thin clients: each tap sends a request to a server, and the screen waits for the answer. The app has not failed; it never had the data it needed in the first place.

An app that works offline is built the other way round. It assumes the network may be absent and treats a working connection as something to use when it is there.

Local data storage on the device

An offline app keeps a local copy of the data the person needs on the device, and that copy is the first step. Phone apps usually store it in an embedded database such as SQLite, which runs inside the app with no server. Web apps can use IndexedDB in the browser. The app reads from this local copy, so screens load at once whether or not there is a connection.

Deciding what to keep is a design question. A field technician’s app might hold today’s jobs, the manuals for the equipment on them, and the forms to fill in, but not the company’s entire history. The local copy has to fit on the device and be refreshed when a connection allows.

Offline writes and the outbox queue

When a person makes a change offline, the app writes it to the local database straight away and shows it as done. This is sometimes called an optimistic update. The change also goes into a queue, often called an outbox, of things that must reach the server.

When a connection returns, the app works through the outbox. Each change carries a stable identifier, so if the app sends it, loses the connection before hearing back, and sends it again, the server can recognise the repeat and apply it once. This property is called idempotency, and offline apps depend on it, because retries are normal rather than exceptional.

Merging changes after reconnecting

When a device reconnects, the app has to merge what it did with what happened elsewhere, because other people may have changed the same data while it was offline. Sometimes the changes touch different things and combine cleanly. Sometimes they collide, and the app needs a rule for which change wins, or a way to merge both.

How does offline sync work? and How are sync conflicts resolved? cover this in detail.

Direct data sharing between nearby devices

Apps can exchange data directly between devices without internet, over Bluetooth Low Energy or a local network, and sometimes relay through other devices in a mesh. Syncing with a server only helps once the server is reachable. If two people are side by side in a basement, on a ship, or at a site with no coverage, neither can reach the server, but both may need the same information now.

The server still becomes the system of record when it is reachable again; the direct link covers the time in between.

Offline-first app design principles

Offline support is easier when it is part of the design from the start. It is hard to add to an app built around constant requests, because the assumption that the server answers is spread through every screen. Designing it in means:

  • Show sync state honestly. Let people see what is saved on the device, what is waiting to send, and what has been confirmed by the server.
  • Separate local success from final success. Saving a record on the device is not the same as the backend accepting it. The app should know the difference and handle a later rejection.
  • Decide what needs a live answer. Payments, unique bookings, and permission changes may need to wait for a connection. Most other work does not.
  • Test without the network. Use airplane mode, slow and flaky connections, and reconnection after long gaps, rather than only a working connection that happens to drop.

Frequently asked questions

Can a web app work offline?

Yes, within limits. A service worker can cache the app's files and answer requests when there is no connection, and IndexedDB can store data in the browser. Browsers do not let web pages open Bluetooth links freely in the background, so device-to-device work usually needs a native app.

What should still require a connection?

Anything where one central authority must decide at the moment it happens, such as charging a card or claiming the last unit of stock. An offline app can record the request and complete it when it reconnects, but it should not pretend the decision has been made.

What is an outbox in an offline app?

It is a queue of changes that must reach the server. The app writes each change to the local database straight away, adds it to the outbox, and works through the outbox when a connection returns.

Why does idempotency matter for offline apps?

Retries are normal rather than exceptional. Each change carries a stable identifier, so if the app sends it, loses the connection before hearing back, and sends it again, the server can recognise the repeat and apply it once.

Which database do mobile apps use to store data offline?

Phone apps usually store it in an embedded database such as SQLite, which runs inside the app with no server. Web apps can use IndexedDB in the browser.

How should you test an app for offline use?

Use airplane mode, slow and flaky connections, and reconnection after long gaps, rather than only a working connection that happens to drop.

Sources

  • About SQLite. The embedded database most phone apps use for local storage
  • IndexedDB API. Local storage for web apps
  • Service Workers. The W3C specification that lets web apps load and handle requests offline
  • What the SDK handles. Offline Protocol's split between the SDK, your application, and your backend

Build it with Offline Protocol

Offline Protocol adds the device-to-device part to an offline-capable app, messages, shared documents, and service calls between nearby devices, while your backend stays the system of record. The docs explain what the SDK handles and what stays with you.

Read what the SDK handles