Offline-first and sync

Offline-first vs local-first

Offline-first and local-first both keep an app working without a connection, but they put the source of truth in different places. An offline-first app works from a local copy and syncs it back to a server, which stays authoritative. A local-first app treats the data on the user's own devices as primary, and any server is one more copy.

Learning objectives

After reading this article you will be able to:

  • Distinguish offline-first from local-first by where the source of truth lives
  • List the seven ideals of local-first software
  • Choose between offline-first and local-first for a given kind of data

Offline-first

An offline-first app is designed on the assumption that the connection may be missing. It keeps a local copy of the data it needs, reads and writes that copy, and queues changes to send to a server when it can. The person using it is not blocked by the network.

The server, though, stays in charge. It holds the authoritative copy, applies the business rules, and can reject a change that was made offline. The local copy is a well-managed cache plus a list of pending work. Most offline-capable business apps work this way: field service, inspections, delivery, and point-of-sale apps that must keep working through an outage and report back afterwards.

Local-first

Local-first is a stronger idea. The term comes from a 2019 essay by Martin Kleppmann, Adam Wiggins, Peter van Hardenberg, and Mark McGranaghan at the research lab Ink and Switch, titled Local-first software: You own your data, in spite of the cloud. It sets out seven ideals:

  1. No spinners: your work at your fingertips.
  2. Your work is not trapped on one device.
  3. The network is optional.
  4. Seamless collaboration with your colleagues.
  5. The Long Now.
  6. Security and privacy by default.
  7. You retain ultimate ownership and control.

In a local-first app, the copies on people’s devices are the primary data. Devices sync with each other, directly or through a server, but a server is a helper, not the owner. If the company behind the app shut its servers down, the data and the app would still work.

The essay points to conflict-free replicated data types (CRDTs) as a promising foundation for these ideals. CRDTs, formalised by Shapiro, Preguiça, Baquero, and Zawirski in 2011, are data structures that let copies edited independently merge into the same result without a central coordinator.

Side by side

Offline-firstLocal-first
Source of truthThe serverThe data on people’s devices
Role of the serverOwner of the data and its rulesOptional helper for relay, backup, or sign-in
Offline editsQueued and confirmed or rejected laterFinal on the device, merged with other copies
ConflictsUsually settled by the serverUsually merged automatically, often with CRDTs
If the server goes away for goodThe app stops working fullyThe app and its data keep working
Common fitBusiness apps with a system of recordPersonal and collaborative tools, documents, notes

Where they overlap

In practice the line is blurry. Both keep a local copy, both sync, and both need a plan for edits that happened apart. Many systems are offline-first for some data and local-first for other data. A delivery app might treat orders as offline-first, because the backend decides what was delivered and billed, while treating a shared checklist on the vehicle as local-first, because the crew needs it to merge cleanly whatever the connection does.

How to choose

Ask where the final decision has to be made.

  • If a central system must approve or reject each change, such as an order, a payment, or a booking, design offline-first. Let people work locally, but keep the server as the judge and show what is still pending.
  • If people own the data and need to work on it together across devices, such as notes, drafts, plans, or checklists, local-first gives a better result. Edits merge instead of waiting for permission.

Device-to-device sync fits both. It matters most when several people are offline together and need the same current state before anyone can reach a server.

Frequently asked questions

Is local-first the same as offline-first?

No. Both work without a connection, but an offline-first app still treats its server as the source of truth, while a local-first app treats the copies on people's devices as primary and can keep working even if the server goes away for good.

Do local-first apps still use servers?

Often, yes. A server can relay changes between devices that are rarely online together, keep a backup, or help with sign-in. In a local-first design it is one more copy of the data, not the place where the data has to live.

Sources

Build it with Offline Protocol

Offline Protocol's replicated documents give an app shared state that devices edit offline and merge when they meet, directly or through a relay, alongside the backend you already run. The shared state guide walks through it.

Read the shared state guide