// lab.track = "exp-02" · 9 min read
Distributed Systems & Collaboration

Local-First Collaboration: Decentralized Consistency with CRDTs

Can real-time multi-user synchronization work without a centralized database lock?

// core_questionPublished: 2025-02-01

Can real-time sync work without a central server?

Local-first software treats the user's local device as the primary source of truth rather than a dumb terminal waiting on remote cloud approval. By pairing local storage with Conflict-free Replicated Data Types (CRDTs), applications achieve zero-latency local interactions and guaranteed mathematical convergence.

The Broken Promise of Pure Cloud Architecture

Cloud-centric applications make a dangerous assumption: continuous, uninterrupted high-speed internet connectivity. When the network drops on a train, in a flight, or in a cellular dead zone, traditional web apps freeze, discard work, or display modal error alerts. Even when connected, every keystroke or canvas movement is delayed by the round trip required to obtain server consensus.

The Local-First Manifesto in Practice

Local-first software stores all user data locally on the client device first (using IndexedDB, SQLite in WASM, or native storage). All read and write operations execute immediately against local memory. The network is utilized purely as an asynchronous synchronization bus rather than a prerequisite for basic operation.

Mathematical Convergence via CRDTs

The core mathematical breakthrough enabling local-first software is the Conflict-free Replicated Data Type (CRDT). Unlike Operational Transformation (OT)—which requires a centralized sequencer to reorder operations—CRDTs possess mathematical properties of commutativity (order does not matter), associativity (grouping does not matter), and idempotence (re-applying does not duplicate). Two peers who receive the same set of mutations in completely different orders will always arrive at the exact same state.

// Simplified observed-remove set (OR-Set) state transition logictypescript
// Abstract CRDT state merge demonstration
interface ElementTag<T> {
  value: T;
  tag: string; // Globally unique lamport timestamp + client id
}

class ORSet<T> {
  private addSet = new Map<string, ElementTag<T>>();
  private removeSet = new Set<string>();

  add(value: T, clientId: string): string {
    const tag = `${Date.now()}-${clientId}-${Math.random().toString(36).slice(2)}`;
    this.addSet.set(tag, { value, tag });
    return tag;
  }

  remove(tag: string): void {
    this.removeSet.add(tag);
  }

  read(): T[] {
    const items: T[] = [];
    for (const [tag, item] of this.addSet.entries()) {
      if (!this.removeSet.has(tag)) items.push(item.value);
    }
    return items;
  }

  merge(remote: ORSet<T>): void {
    // Commutative set union
    for (const [tag, item] of remote.addSet.entries()) {
      if (!this.addSet.has(tag)) this.addSet.set(tag, item);
    }
    for (const tag of remote.removeSet) {
      this.removeSet.add(tag);
    }
  }
}

Taming the State Growth Challenge

The classic criticism of CRDTs is metadata tombstone explosion: because deleted elements must be remembered to prevent resurrecting deleted state from lagging peers, document history can grow continuously. In our research on Nexus, we resolve this through periodic epoch compaction. When all connected peers acknowledge a synchronized vector state, past tombstones can be safely scrubbed without risking divergence.

Architectural Takeaways
  • 01.Local-first software provides instantaneous zero-millisecond UI latency because every operation modifies local memory first.
  • 02.CRDTs eliminate central server locking bottlenecks, enabling seamless peer-to-peer and offline-first collaboration.
  • 03.Tombstone compaction strategies are essential in production to prevent unbounded memory growth over months of collaborative editing.

Applied in our production systems & services

06 / intake

Building software with complex technical constraints?

We turn experimental architectures into production-grade systems for ambitious companies.