Local-first data

Can local-first apps still have a backend?

Yes. Local-first software does not mean no servers; it changes their job. The device holds the primary copy and keeps working when no server is reachable, while a backend can relay changes between devices that are rarely online together, keep backups, connect to other systems, and act as the authority for rules that need one.

TL;DR

A backend fits a local-first app as long as people can open, edit and keep their data with that server switched off. To keep it off the critical path, use data that merges the same way over any route, treat the server's copy as one replica, and keep each record on the device until the backend has durably accepted it.

Learning objectives

After reading this article you will be able to:

  • Explain why servers in a local-first app play a supporting role, not the source of truth
  • List the jobs a backend can do for a local-first app
  • Describe design choices that keep a backend off the critical path

Servers in local-first apps

Local-first is sometimes read as “no backend”, but the Ink & Switch essay that defined the idea says the opposite. The key difference between traditional systems and local-first ones, it argues, is not an absence of servers but a change in their responsibilities: servers are in a supporting role, not the source of truth.

The essay calls these supporting servers cloud peers: servers that help client apps without being on the critical path. An app that cannot open a document, save an edit, or show its data until a server answers has put the server back on the critical path. An app that can do all of that with the network off, and uses the server when it is there, has kept it in a supporting role.

Backend jobs in a local-first app

A backend can relay changes between devices that are not online together, keep backups, bridge to other services, act as the authority for rules that need one, and stay the system of record for everything else.

Relay between devices that are not online together. If one person shares a document and closes their laptop before the other person connects, direct peer-to-peer sync has nobody to sync with. The essay’s suggested fix is a cloud peer that stores a copy of the document and forwards it to other peers when they come online. Automerge’s project publishes a small sync server for exactly this role: it stores documents in a data directory and relays them over WebSocket. Its README describes it as an unsecured Express app, so an app that keeps private data on such a server has to add its own access control.

Keep backups and archives. A server copy protects against a lost or broken device, and the essay notes this is especially useful for phones and other devices with limited storage.

Bridge to other services. The essay’s examples include a bridge to traditional server APIs, such as weather forecasts or stock tickers, and a provider of burst computing for heavy jobs like rendering video on a GPU.

Act as the authority for rules that need one. Merging guarantees that copies converge, not that the result is valid. Two people can each book the last slot offline, and both copies will merge cleanly into a state that breaks the rule. A backend that checks such rules when changes arrive, and rejects one of them, is a straightforward way to hold the line. How sync conflicts are resolved covers when to hand a decision to an authority.

Stay the system of record for everything else. Local-first documents can cover the work people do together in the field while existing databases keep payroll, billing, inventory and history.

Keeping the backend off the critical path

Three design choices keep a backend helpful without making it required: a data model that does not care about the route, a server copy treated as one replica, and clarity about what each handoff means.

Use a data model that does not care about the route. Automerge describes itself as network-agnostic: it works over client/server connections such as WebSocket, peer-to-peer connections such as WebRTC, or entirely local links such as Bluetooth, and an Automerge file can even travel as an email attachment or on a USB drive and still merge. When the data merges the same way whatever carried it, the server becomes one route among several. Ditto’s documentation makes the same point for its product: sync works the same whether a device is syncing with other devices in the mesh or with its server. Peer-to-peer sync vs cloud sync compares the routes.

Treat the server’s copy as one replica. The server can be a peer that receives and merges changes like any device. Compare a server-authoritative design: PowerSync’s documentation describes a backend endpoint that applies client writes to the source database, and changes the server does not confirm are removed from the client. That is an offline-first design: in it the server’s copy decides, so it is not local-first in the Ink & Switch sense.

Be clear about what each handoff means. When local work reaches a backend, “sent”, “received” and “committed” are different events, and a device should keep its record until the backend has durably accepted it. Delivered, accepted, committed explains the distinction. Offline Protocol’s backend delivery guide applies this to records retained on devices: it asks for stable event IDs, an adapter that maps events into the destination’s schema with idempotency keys or duplicate-safe writes, and a record of the destination’s durable acceptance for each event ID. It warns against clearing the source merely because the SDK reported delivery.

Backend-off test for local-first apps

To check whether a backend is in a supporting role, turn it off and use the app:

  • Can a person open their data, edit it, and see their edits after a restart?
  • Can two people nearby still share changes, if the app supports that?
  • When the server comes back, do the copies converge without anyone re-entering work?
  • Are the rules that need an authority clearly marked as waiting, rather than silently assumed to have passed?

If the answers are yes, the app has a backend and is still local-first.

Frequently asked questions

If there is a server, what makes the app local-first?

Whether the app depends on it. In a local-first app the device's copy is primary and the app keeps working, reading and writing when the server is unreachable or gone. The server holds a secondary copy and helps, but it is not where changes have to land to count.

Can the backend reject a change made offline?

It can refuse to act on it, for example by not confirming a booking that breaks a rule. Because the change already exists on the devices, the app then needs a visible way to show the rejection and offer a next step.

Does a local-first app need a sync server?

Not for devices that are online together, since they can sync directly. A server helps when one person shares a document and goes offline before the other connects, because a cloud peer can store a copy and forward it when the other peer comes online.

Is the Automerge sync server safe for private data?

Not on its own. Its README describes it as an unsecured Express app, so an app that keeps private data on such a server has to add its own access control.

Is a server-authoritative sync design local-first?

No. In the design PowerSync's documentation describes, a backend endpoint applies client writes to the source database and changes the server does not confirm are removed from the client. The server's copy decides, which makes it offline-first rather than local-first in the Ink & Switch sense.

When can a device clear a record it has sent to the backend?

Only once the backend has durably accepted it. Offline Protocol's backend delivery guide asks for a record of the destination's durable acceptance for each event ID and warns against clearing the source merely because the SDK reported delivery.

Sources

Build it with Offline Protocol

The backend delivery guide shows how to retain records on devices while offline and hand them to your existing system of record through an adapter, recording when the backend has durably accepted each one.

Read the backend delivery guide