Designing for the Offline-First Future: Sync Engines and CRDTs
"Why users expect instant loads and zero spinners even when traversing airplane WiFi or subway tunnels, and how conflict-free data types make it possible."
Elena Rostova
Staff Systems Architect
The Network is an Intermittent Luxury
We design software while tethered to gigabit fiber connections in urban offices, forgetting that real human beings use our software on commuter trains entering tunnels, on spotty airport Wi-Fi, or in rural regions with sporadic packet loss.
An application that renders a blank white screen or displays a spinner when connectivity drops fails its primary duty.
Conflict-Free Replicated Data Types (CRDTs)
How do you allow two users—or a single user across two disconnected devices—to write and edit notes concurrently without experiencing merge conflicts or losing data when they reconnect?
// State-based CRDT LWW-Register (Last-Write-Wins)
export class LWWRegister<T> {
constructor(
public value: T,
public timestamp: number,
public peerId: string
) {}
merge(incoming: LWWRegister<T>): LWWRegister<T> {
if (incoming.timestamp > this.timestamp) {
return incoming;
}
if (incoming.timestamp === this.timestamp && incoming.peerId > this.peerId) {
return incoming;
}
return this;
}
}
By storing local changes in IndexedDB or SQLite first and treating the network as an asynchronous synchronization channel, your application becomes invincible against packet drops and network outages.
Elena Rostova
Obsessed with distributed latency, local-first protocols, and mechanical sympathy.
Discourse & Reader Notes (0)
Contribute a perspective to this dispatch