Google Docs vs. The Database
Imagine two people editing the same sticky note at the same time. In the physical world, you'd end up with a torn note. In a traditional database, the system solves this by making one person wait — it locks the note, lets one person write, then lets the other. This works fine for a bank ledger, but it's terrible for real-time collaboration.
In a tool like Google Docs, Figma, or Notion, you want both people to type simultaneously and see each other's changes instantly — even if one of them is on a train with no internet. When they reconnect, their changes must merge automatically, and every device must end up showing the exact same document.
This is the multiplayer problem: how do you let multiple replicas of data diverge temporarily and then converge to a single agreed-upon state, without a central referee deciding who wins?
The Traditional Approaches and Why They Fall Short
Before CRDTs, distributed systems used two main strategies:
1. Operational Transformation (OT): Used by early Google Docs. Every operation (insert character at position 5) is transformed relative to concurrent operations before being applied. It works, but the transformation logic is notoriously complex and requires a central server to sequence operations. Implementing OT correctly is considered one of the hardest problems in distributed systems.
2. Last-Write-Wins (LWW): Pick the operation with the latest timestamp and discard the other. Simple, but it silently destroys data. If two users edit simultaneously and clocks aren't perfectly synchronized, one user's work disappears with no warning.
Enter CRDTs
Conflict-free Replicated Data Types (CRDTs) are data structures — Sets, Counters, Maps, Sequences — engineered with special mathematical properties that make merging automatic and conflict-free.
They guarantee Strong Eventual Consistency (SEC):
- Any replica can be updated independently — online or offline.
- Updates can arrive in any order at any replica.
- Once all replicas have received all updates, every machine is mathematically guaranteed to reach the exact same state — no manual conflict resolution, no "git merge" prompt.
CRDTs are used in production at scale: Redis (CRDT-based geo-replication), Riak (distributed key-value store), Apple Notes (offline sync), Figma (multiplayer canvas), and Automerge (a popular open-source CRDT library for JSON).
Interviewers often ask: "How does Google Docs handle concurrent edits?" The correct answer distinguishes between Operational Transformation (the original approach, requires a central server) and CRDTs (the modern approach, works peer-to-peer). Knowing that Google Docs originally used OT and that newer collaborative tools like Figma lean on CRDT-inspired approaches signals genuine depth.
Key Point: CRDTs shift conflict resolution from runtime arbitration (a server deciding who wins) to design-time mathematics (structuring operations so conflicts are impossible by construction).