Quick revision
The short answer
The session server did work proportional to edits times viewers: 400 edits per second sent to 3,000 connections is 1.2 million messages per second through one process, so its queues grew and edits lagged by 20 seconds. Edits were lost because they were acknowledged before they were durable, or because clients discarded unacknowledged operations when they reconnected. The fix is to keep one ordering owner per document but move fan-out to a separate relay tier with batching, send read-only viewers throttled updates, cap concurrent editors, store every operation durably before acknowledging it, have clients resend pending operations after reconnecting, and let a new owner take over through a lease and continue from the stored log.
What to remember
In this answer, we saw that one popular document overloaded its owner because broadcast work grows with edits times viewers, here over a million messages per second. Separating ordering from fan-out, batching operations, giving viewers throttled updates and capping editors brings the owner's work back to the edit rate. Edits were lost because acknowledgements did not mean durable or clients dropped pending operations, so we store before acknowledging and keep pending operations on the client. A lease with fencing lets a new owner continue from the stored log while clients rebase and resend.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The session server did work proportional to edits times viewers: 400 edits per second sent to 3,000 connections is 1.2 million messages per second through one process, so its queues grew and edits lagged by 20 seconds. Edits were lost because they were acknowledged before they were durable, or because clients discarded unacknowledged operations when they reconnected. The fix is to keep one ordering owner per document but move fan-out to a separate relay tier with batching, send read-only viewers throttled updates, cap concurrent editors, store every operation durably before acknowledging it, have clients resend pending operations after reconnecting, and let a new owner take over through a lease and continue from the stored log.
Why this question is asked
Most documents have a handful of editors, so a design with one session owner per document works for years and then fails on one unusual day: the company-wide announcement, the incident document, the live event sheet. Interviewers use this scenario because it tests two separate skills together, scaling a hot spot and reasoning precisely about durability during failure. In this answer, we will do the arithmetic that explains the overload, find out exactly how edits were lost, separate ordering from fan-out, treat viewers differently from editors, fix the durability rule, and design the owner failover.
1Why One Document Saturated One Server
In the original design, one session owner per document receives every operation, assigns it a revision, and sends it to every connected client. The ordering work grows with the number of edits, which is fine: 400 operations per second is little. The broadcast work grows with edits times connections. With 400 edits per second and 3,000 open connections, the owner had to serialise and send about 1.2 million messages per second, plus presence updates for cursors, which are often even more frequent.
No single process does that comfortably on top of ordering. CPU reached 100 percent, the outgoing queues grew, and every new operation waited behind seconds of old messages. That is where the 20-second lag came from. Notice that the problem was not the 400 editors; it was the 2,600 people who were only reading.
2How the Edits Were Lost
Losing edits after a restart means some operation was considered safe by the client but was not stored. There are two usual causes, and post-incident analysis should check both. First, the server acknowledged operations once they were applied in memory and wrote them to the log in batches, say every few seconds; under load the batches fell behind, and the crash took about 30 seconds of acknowledged but unwritten operations with it. Second, the client may have thrown away operations it had sent but not yet seen acknowledged when its connection reset, assuming the server had them.
8 messages in order. Play them, or step through them one at a time.
The acknowledgement promised durability that did not exist yet.
Either way, the rule that was broken is the same: an acknowledgement must mean the operation is durable, and the client must not forget anything until it has that acknowledgement.
3Separate Ordering From Fan-Out
We keep exactly one ordering owner per document, because a single order is what keeps every copy consistent. But we take broadcasting away from it. The owner publishes each stored operation once to a relay tier, for example a set of fan-out servers subscribed through a pub/sub system such as Redis Pub/Sub, NATS or an internal relay, and clients connect to relay servers rather than to the owner. With 3,000 clients spread over 10 relay servers, the owner sends 400 messages per second to 10 subscribers, and each relay sends to 300 clients.
We also batch. Instead of sending every operation separately, the owner groups the operations of each 50 ms time slice into one message. That turns 400 messages per second into 20 per client per second, each slightly larger, which cuts the per-message overhead of serialisation, system calls and WebSocket framing by about 20 times, while the added delay of 50 ms is not noticeable.
- 3,000 clients400 editors, 2,600 viewers
- Relay servershold the WebSockets, fan out batches, about 300 clients each
- Pub/sub channel per documentone publish per 50 ms batch
- Ordering ownerassigns revisions, writes log, acks after storing
- Durable operation logreplicated, group commit every few ms
5 layers, from the top down. Step through them one at a time.
The owner's work now grows with edits, not with edits times viewers.
4Treat Viewers and Editors Differently
A reader of an announcement does not need every keystroke within 200 ms. We give read-only viewers a cheaper stream: a fresh snapshot or a compact diff once per second, and cursors only for a small number of people. That alone removes most of the load, because 2,600 of the 3,000 clients were viewers.
We also cap concurrent editors per document, for example at 200, and show anyone beyond the cap a clear message that the document is in view mode with an option to comment. Comments can go through their own, lower-priority path, since a comment appearing a second later is fine. Product teams usually accept a cap once they see that 400 people typing in one document is rarely useful.
5Make the Acknowledgement Mean Durable
The owner must write each operation to a durable, replicated log before it acknowledges it. To keep throughput, it uses group commit: operations arriving within a few milliseconds are written together in one append, and all of them are acknowledged after that append succeeds. A replicated log such as Kafka with acks=all, or a database write confirmed by its replicas, gives durability beyond one machine.
The client keeps every operation it has sent but not seen acknowledged. After a reconnect, it asks the new owner which revisions it missed, transforms its pending operations against them, and resends them with their base revision and their client operation id. The owner ignores ids it has already stored, so a resend after a lost acknowledgement creates no duplicate.
6Failing Over the Owner
Ownership is a lease in a coordination store such as etcd or ZooKeeper, renewed every few seconds. When an owner stops renewing, another instance acquires the lease and receives a fencing token, a number that increases with each new lease. It loads the latest snapshot and the log after it, and continues from the last stored revision. The log rejects writes carrying an older fencing token, so a paused old owner that wakes up cannot append conflicting revisions.
- Old owner stops renewing its leasecrash or long pause
- New owner acquires the leasefencing token 42
- Load snapshot plus loglast stored revision 9090
- Clients reconnect and fetch missed opsfrom their last known revision
- Clients rebase and resend pending opswith client operation ids
- Owner skips ids already storedstores and acks the rest
6 steps in order. Play them, or step through them one at a time.
Clients see a pause of a few seconds, reconnect, rebase their pending operations and resend them. With durable acknowledgements and client-side retention, the lost-edits incident cannot happen again, and we test it on purpose by killing owners of busy documents in a load test.
7Follow-up questions
Why not shard one document across several owners?
Because a document needs one order of operations. We could split by section, but edits that move text between sections would then need coordination across owners, which brings back the hard problems. Keeping one owner and moving fan-out, viewers and comments off it removes nearly all of the load.
How do you notice a hot document before it fails?
Track per-document connection counts, operations per second and outgoing queue depth on each owner, and alert when one document exceeds thresholds such as 500 connections. The system can then switch that document to view mode for new joiners and move its fan-out to more relay servers automatically.
What would you tell the users who lost edits?
That we found the cause, which was acknowledging before storing, what we changed, and, where possible, which revisions were affected. Because the log records authors and revisions, we can identify the gap and tell people exactly which window to check.
8Conclusion
In this answer, we saw that one popular document overloaded its owner because broadcast work grows with edits times viewers, here over a million messages per second. Separating ordering from fan-out, batching operations, giving viewers throttled updates and capping editors brings the owner's work back to the edit rate. Edits were lost because acknowledgements did not mean durable or clients dropped pending operations, so we store before acknowledging and keep pending operations on the client. A lease with fencing lets a new owner continue from the stored log while clients rebase and resend.
Open with
The arithmetic explains the overload. One owner orders and broadcasts every operation, so the work is edits times connections: 400 edits a second to 3,000 clients is about 1.2 million messages a second, plus presence.
Then, if they want more
CPU saturated, queues grew, and edits lagged 20 seconds. The lost edits mean the acknowledgement did not mean durable: the owner probably acked after applying in memory and wrote the log in batches, or clients dropped unacknowledged operations on reconnect.
I would keep one ordering owner per document but move fan-out to a relay tier through pub/sub, so the owner publishes once per batch, and batch operations into 50 ms slices. Read-only viewers get a snapshot or diff once a second, and I cap concurrent editors with a clear view-mode message.
For durability, the owner writes to a replicated log with group commit before acking, and clients keep every unacknowledged operation and resend it with its base revision and an id the server deduplicates. Ownership is a lease in etcd with a fencing token, so a new owner loads snapshot plus log, continues, and a stale owner cannot write. Then I would test failover under hot-document load.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why did one popular document overload its session server and lose edits, and how do you...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/d71d48e24c/