On this page
Shifting the paradigm from cloud-centric to user-centric data synchronization patterns.
01.Why the cloud-first default feels wrong
For most of my career the architecture of a web application has been settled before anyone draws a diagram. The data lives in a database in a region somewhere. The browser asks for it, waits, renders what comes back and asks again when anything changes. Every click that matters is a round trip. We have become extremely good at making that round trip fast, with edge caches, connection pooling, streaming responses and optimistic updates, but we rarely question the premise that the server is where the truth lives and the device is a window onto it.
I build data platforms for a living, so I am not hostile to servers. I like them. But the longer I work on systems that move data between places, the more I notice how much effort goes into hiding the network from people who never asked to know about it. A note-taking app that shows a spinner on a train. A form that loses its contents because a token expired while someone was typing. A dashboard that is unusable on a flaky hotel connection even though the numbers it needs were downloaded ten minutes ago. None of these are bugs in the usual sense. They are the natural consequence of putting the source of truth on the far side of an unreliable link.
Local-first is a name for a different premise. The idea is that the primary copy of a user's data lives on their device, in a real database, and the application reads and writes it directly. The network becomes a way to synchronise copies, share them with other people and back them up, rather than a precondition for doing anything at all. The server does not disappear, but its job changes from gatekeeper to peer with extra responsibilities.
What makes this interesting now, rather than ten years ago, is that the pieces have become practical. Browsers can run SQLite compiled to WebAssembly, with persistent storage that survives reloads. Devices have far more storage and memory than most applications will ever use for one person's data. And the research on conflict-free replicated data types, the maths that lets independent copies of data converge without a central referee, has matured into libraries that working engineers can reach for. The question has moved from whether it can be done to whether it is worth the trade-offs for a given product.
I have spent the last while building small tools this way, mostly for my own use, and I want to write down what I have learned: what local-first asks of you, how merging actually works, where a server is still essential, and what it is like to live with in production. I will try to be honest about the costs, because there are real ones.
02.What local-first actually asks of you
The first shift is in where you put your reads. In a conventional app, every screen has a loading state because every screen fetches. In a local-first app, a screen queries a local database and gets an answer in a millisecond or two. That sounds like a small implementation detail, but it changes how you design. Loading skeletons largely vanish. Search can run on every keystroke without debouncing against a rate limit. Filters and sorts become instant, which quietly encourages users to explore their own data in ways they never would through a slow interface.
The second shift is in your writes. When a user changes something, you write to the local database and you are done, as far as the interface is concerned. The change is durable on the device immediately. A background process then takes responsibility for getting it to other replicas. This is the part that feels uncomfortable at first, because you have to accept that for some period of time, different devices will disagree about the state of the world. There is no moment where the server says yes and everything becomes consistent at once.
That discomfort is the heart of the matter. A cloud-first system gives you a comforting illusion of a single timeline: requests arrive at the database in some order and each one sees the result of the ones before it. A local-first system admits that there are many timelines, one per device, and that they will be reconciled later. Your data model has to be designed for reconciliation from the beginning. You cannot bolt it on.
In practice this means a few concrete disciplines. Every record needs an identifier generated on the device, not by the server, so that two offline devices can create records without colliding. Random UUIDs or ordered variants of them work well. Every change needs enough metadata to decide how it relates to other changes: at minimum, which replica made it and when, in a sense of time that the replicas can agree on. And deletes need to be represented as changes in their own right, usually as tombstones, because a record that simply vanishes cannot be told apart from one that has not arrived yet.
The mechanism that carries local changes outward is usually some form of outbox. Every write to the local database also appends a row to a queue table in the same transaction, so a change and its record of needing to be sent can never drift apart. A sync worker reads from the front of that queue, sends batches to the server and marks them acknowledged once the server confirms receipt. If the app is closed halfway through, nothing is lost: the queue is still there on the next launch. Anyone who has built a reliable event publisher on top of a relational database will recognise the pattern, and it works just as well with SQLite in a browser as it does with PostgreSQL on a server.
The third shift is in how you think about schema. On a server you control migrations: you run them once, in order, and every query afterwards sees the new shape. On a fleet of devices, some of which have been offline for weeks, you have old clients writing old shapes into a sync stream that new clients have to read. Schema changes become a protocol concern, closer to evolving an event format in a streaming system than to altering a table. I will come back to this, because it is one of the places where my data engineering habits helped the most.
None of these disciplines is exotic. Anyone who has built an event-driven pipeline, a mobile app with offline support or a multi-region database has met versions of them. What is new is applying them to ordinary web applications, where for years we have been able to pretend that a single database would sort everything out for us.
03.Merging without a referee
The hardest question in any replicated system is what happens when two copies change the same thing independently. Cloud-first systems mostly avoid the question by refusing concurrent writes: the database takes locks, or the second writer gets a conflict error and has to retry. Local-first systems cannot do that, because the whole point is that devices keep working when they cannot talk to each other. So they need merge rules that every replica applies the same way, producing the same result regardless of the order in which changes arrive.
That requirement has a precise shape. A merge function that makes replicas converge must be commutative, so merging A into B gives the same result as merging B into A. It must be associative, so the grouping of merges doesn't matter. And it must be idempotent, so receiving the same change twice has no further effect. If your merge satisfies those three properties, you can deliver changes in any order, over any transport, with duplicates and delays, and every replica that has seen the same set of changes will end up in the same state. Data structures built around such merges are what the literature calls conflict-free replicated data types.
The simplest useful example is a last-write-wins map. Each key holds a value together with a stamp recording when and where it was written. When two replicas disagree about a key, the one with the later stamp wins. The subtlety is entirely in the word later. Wall clocks on different devices drift, sometimes badly, so you cannot just compare timestamps and hope. You need a total order that every replica computes identically. The usual trick is to pair a time with a replica identifier and break ties on the identifier, and to make sure a replica never issues a stamp earlier than one it has already seen.
Here is a small version of that idea in TypeScript. It is deliberately minimal, but it is correct for what it claims to do:
export type Stamp = { time: number; replica: string };
// A null value is a tombstone, so deletes merge like any other write.
export type Entry<V> = { value: V | null; stamp: Stamp };
export type LwwMap<V> = Record<string, Entry<V>>;
// Total order: later time wins; the replica id breaks ties the same way everywhere.
export function isNewer(a: Stamp, b: Stamp): boolean {
if (a.time !== b.time) return a.time > b.time;
return a.replica > b.replica;
}
// Never reuse a time: stay ahead of every stamp this replica has seen.
export function tick(latestSeen: Stamp, replica: string, now = Date.now()): Stamp {
return { time: Math.max(now, latestSeen.time + 1), replica };
}
export function write<V>(map: LwwMap<V>, key: string, value: V | null, stamp: Stamp): LwwMap<V> {
const current = map[key];
if (current && !isNewer(stamp, current.stamp)) return map;
return { ...map, [key]: { value, stamp } };
}
// Commutative, associative and idempotent: replicas converge in any delivery order.
export function merge<V>(local: LwwMap<V>, remote: LwwMap<V>): LwwMap<V> {
let result = local;
for (const [key, entry] of Object.entries(remote)) {
result = write(result, key, entry.value, entry.stamp);
}
return result;
}There are a few details worth pointing out. The tick function is a simplified hybrid clock: it uses the device's current time when that is ahead of everything seen so far, and otherwise nudges forward by one. That keeps stamps close to real time for readability while guaranteeing they only move forward, even if a device's clock jumps backwards. The tie-break on replica identifier is arbitrary, but it is the same arbitrary choice on every device, which is all convergence needs. And deletes are ordinary writes of a null value, so a delete and a concurrent edit are resolved by the same rule as any two edits.
Last-write-wins is blunt. If two people edit different fields of the same record, a per-record register would throw one person's work away, which is why the example keeps a stamp per key rather than per record. For text, where two people might type into the same paragraph, you need something richer: sequence CRDTs that give every character a stable position, so concurrent insertions interleave sensibly instead of overwriting each other. For counters you want structures where each replica tracks its own increments and the merge takes the maximum per replica. The general lesson is that you choose a merge rule per kind of data, the same way you choose a column type.
Because the correctness of the whole system rests on those three properties, I test them directly rather than trusting that the code looks right. Property-based tests are ideal for this. Generate a few random sets of changes from a few imaginary replicas, merge them in every order and grouping you can think of, deliver some of them twice, and assert that every path ends in the same state. A test like that finds subtle mistakes quickly, such as a tie-break that compares the wrong field or a delete that loses to an older edit. It is some of the most valuable test code I have written, and it is short.
In a local-first system, a conflict is not an error to be handled. It is a normal event with a rule you chose in advance.That reframing did more for my design work than any particular library. Once I accepted that concurrent edits are normal, I started asking better questions early. Which fields can safely take the last write? Which ones need to keep both values and ask a human? Which operations are really commutative, like adding a tag, and which only look that way, like setting a status that other logic depends on? Answering those questions up front is much cheaper than discovering them after two users have silently overwritten each other's work.
04.Where the server still earns its place
It would be easy to read all this as an argument against servers, and some of the enthusiasm around local-first does lean that way. I don't think it holds up. In the systems I have built, the server keeps several jobs that the devices cannot do on their own, and doing them well is what makes the local experience trustworthy.
Underneath every one of those jobs sits identity. Devices have to prove who they are before the server will accept their changes or send them anyone else's. The comfortable pattern is the same one any API uses: a short-lived token, refreshed in the background, attached to every sync request. The difference is that a local-first client must keep working when that token expires offline, so the app treats an authentication failure as one more reason sync is paused, not as a reason to log the user out and discard their work.
The first job is being an always-available peer. Two devices that are rarely online at the same time can still sync through a server that holds every change until both have seen it. In practice my sync servers are fairly boring: a PostgreSQL database with an append-only table of changes, indexed by document and by a server-assigned sequence number. Each client remembers the last sequence it received and asks for everything after it. Because the merge on the client is idempotent, the server does not need to be clever about exactly-once delivery. At-least-once is fine, and that makes the whole pipeline much simpler to operate.
The second job is authority over things that must not be merged. Permissions are the obvious example. If a document is shared with you and the owner revokes access while you are offline, your device should not be able to merge its way back in. Anything involving money, quotas, uniqueness across users or legal records belongs in the same category. For these, the server validates changes as they arrive and rejects or quarantines the ones that break a rule. The client has to be designed to handle that rejection gracefully, usually by keeping the change locally with a visible status rather than dropping it.
The third job is backup and recovery. A user's device is a perfectly good primary copy until it falls in a lake. The server's copy of the change log is what lets a new device rebuild the full state, and it is also what lets you restore a document to an earlier point when something goes wrong. Keeping the full history costs storage, but it is the cheapest insurance in the whole design. When I have had to debug a strange state on a user's machine, the ability to replay their change log against a fresh replica has been invaluable.
The fourth job is doing things devices shouldn't: sending email, calling third-party APIs with secrets, building search indexes across many users, and running analytics. These are best treated as consumers of the change stream, the same way a data warehouse consumes events from operational systems. That framing is comfortable for me because it is exactly how I would design an ingestion pipeline. The sync log is a source; everything else subscribes to it.
What changes is the direction of dependency. In a cloud-first app, the device depends on the server for everything, so any server trouble is an outage. In a local-first app, the device depends on the server only for collaboration, durability beyond the device and a few authoritative checks. A server incident becomes a sync delay rather than an outage, and users can keep working through it. That property alone has made me want to build this way more often.
05.Living with it in production
The honest part of any architecture essay is the list of things that hurt. Local-first has its share, and I would rather name them than let anyone discover them in production.
Schema evolution is the biggest. Once changes are flowing between devices running different versions of your app, every change format you ship lives forever. My rule is to treat the sync format like a public API. Fields are only ever added, never renamed or repurposed. Every change carries a schema version. Clients ignore fields they do not understand and preserve them when they rewrite a record, so an old client does not strip data that a newer one wrote. When a real breaking change is unavoidable, I write it as a new document type with a one-way migration that runs on each device, rather than trying to transform history in place. It is the same approach I would take to evolving an event schema in a streaming platform, and for the same reasons.
Storage limits are the second. Browsers are generous, but they are not unlimited, and they can evict data under pressure unless you request persistent storage. Keeping every tombstone and every historical stamp forever will eventually bite. You need a compaction strategy, and compaction in a replicated system is subtle: you can only discard history that every replica has already seen, which means tracking what each replica has acknowledged. For small personal tools I have got away with generous limits and occasional full resyncs. For anything with many collaborators, compaction deserves real design time.
Debugging is the third, and it is more interesting than painful. When a user reports that something looks wrong, there is no single database to query. The state they see is the result of merging a particular set of changes in their particular copy. The tool that saved me every time was the ability to export a replica's change log and replay it locally. Because the merge is deterministic, the replay reproduces their state exactly. I have come to see that as a genuine advantage over many cloud-first systems, where reproducing a user's view often means guessing at the timing of requests.
Observability needs rethinking too. In a cloud-first system, most of what you need to know shows up in server logs and request metrics. In a local-first one, the interesting behaviour happens on devices you cannot see. I have found it worth reporting a small set of sync health figures from each client, with the user's consent and without any document content: how many changes are waiting in the outbox, how long since the last successful sync and how many changes the server rejected. Aggregated, those numbers tell you whether sync is healthy across the fleet long before anyone files a bug report.
Initial load is the fourth. A cloud-first page can render the first screen from a few rows fetched on demand. A local-first app has to get the user's data onto the device before it can be fast, and for a large account that can mean a noticeable first sync. Partial replication helps: sync the documents a user is likely to open first and stream the rest in the background. So does a server-rendered first view for new sessions. But it is a real cost, and it is the one that most often decides whether local-first suits a product.
Finally, there are products that simply should not work this way. If your data is huge and shared by everyone, such as a catalogue, a feed or a search index, there is no sensible notion of each user holding the primary copy. If correctness depends on a global order, as it does with inventory or payments, a central authority is the right tool and pretending otherwise will hurt. Local-first shines when the data naturally belongs to a person or a small group: documents, notes, plans, personal records and the tools that professionals use to do their own work.
When the fit is right, though, the result is hard to go back from. The app opens instantly. It keeps working on a plane. Collaboration feels like editing the same thing rather than taking turns. And the architecture, once you have internalised the merge rules, is often simpler than the cloud-first alternative, because so much of the defensive code around loading, retries and stale caches is no longer needed. I don't think every web application will be built this way, but I am increasingly sure that more of them should be, and that the skills involved are ones data engineers already have.