Part 7 of 8 · 2 min read
Trade-offs
What to say out loud.
Trade-offs and what to say
| Choice | Gain | Cost |
|---|---|---|
| Local apply first | Instant typing | Needs merging |
| OT with a central server | Small metadata, simple ordering | Subtle transform rules, server needed |
| CRDT | Offline and peer-to-peer friendly | More metadata, tombstone clean-up |
| One owner per document | Simple, correct order | Hot documents limited by one server |
| Log plus snapshots | Fast open, recoverable | More storage |
| Presence in memory | Fast, cheap | Lost on a crash (acceptable) |
| Viewer relays | Many viewers | More hops, slight delay |
Interview angle
Answer in your head first, then open it.
Why not lock the document?
It stops simultaneous typing. Small unlocked edits need conflict handling.
What is OT?
Transform each operation against concurrent ones so positions stay right. A server orders everything.
What is a CRDT?
A structure where every character has a unique identity, so edits merge in any order.
How does it scale?
Partition by document id, with one owner server for each document.
What happens on a server crash?
A new owner loads the snapshot and replays the log. Clients resend by revision.
One follow-up to try. "A document has 50,000 viewers." A good reply: editors stay on the owner. Viewers connect to relay servers that subscribe to the owner's broadcast and fan out to viewers, much like the pub/sub of page 1. Viewers see changes with a delay of a few hundred milliseconds. Presence for viewers can be turned off or sampled.
Check yourself: 1. Which choice gives the simplest ordering? 2. Why is presence not stored durably? 3. How do you serve a very popular document?
Words you will meet
| Word | Meaning |
|---|---|
| Replica | One copy of the document, such as one user's screen |
| Convergence | All copies end in the same state |
| OT | Operational transformation |
| CRDT | A data type that merges edits without conflicts |
| Tombstone | A mark that stands for a deleted item |
| Revision | The version number of the document |
| Presence | Who is in the document and where their cursor is |
| Snapshot | A saved copy of the whole document at one revision |