111. Design an online collaborator platform?
Design an online collaboration platform where many users can create or join a shared document and edit it at the same time. The system should show live changes, user presence, cursors, comments, version history, and reconnect users after a network failure. Explain how edits are ordered and merged, how duplicate operations are prevented, how document state is stored, how WebSocket connections are scaled, how offline edits are handled, and how the system recovers when a collaboration server fails.
At a high level, this system lets many users edit the same document in real time. The hard part is keeping every user in the same order while handling reconnects and server failures. I would explain it in four parts: route each document to one Session Owner, commit edits to the Operation Log, broadcast live updates, and recover clients from snapshots plus missed operations. The main trade-off is strong ordering versus more coordination.
The goal is to let many users edit one shared document and see changes quickly. The difficult part is keeping every client in the same order when edits happen at the same time. The system must also handle comments, presence, offline work, reconnects, and server failures. The diagram solves this with one Session Owner per document, Operational Transformation, a durable Operation Log, snapshots, and short-lived connection and presence stores.
- Which user flows and system capabilities are required for the first version?
- What traffic, data volume, latency, and availability targets should I design for?
- Which consistency, security, geographic, and cost constraints matter most?
A user creates a document or joins an existing one through the WebSocket Gateway. The gateway checks authentication, permissions, request limits, and tenant rules.
The Document Router hashes the document_id. It sends every connection for that document to the same Collaboration Session Owner.
The client receives the current snapshot and any operations after the snapshot sequence. This gives the client the latest document state before live editing starts.
The Connection Registry stores which WebSocket node owns each user and device connection. This is short-lived routing data and is updated when clients reconnect.
Each Session Owner holds a lease for one document. The lease contains document_id, owner_epoch, and lease_expiry.
The owner renews the lease with heartbeats. If renewal fails, it must stop accepting new edits.
When another node takes over, it receives a higher owner_epoch. Only the newest epoch may append operations. This stops an old server from writing after a network delay.
The client sends an edit with operation_id and base_sequence. The Session Owner checks permissions and ignores duplicate operation IDs.
The service uses Operational Transformation, or OT. OT changes a new edit so it still works after other users' earlier edits.
The owner assigns the next document sequence. It appends the operation to the Operation Log with document_id, sequence, owner_epoch, and operation_id.
The Operation Log is the source of truth. It rejects writes from an older owner_epoch. The sender is acknowledged only after the log commits the operation.
The Session Owner broadcasts the committed operation directly after the log commit. It does not wait for the Operational Store update.
The current document state may update immediately after. If that update fails, it can be retried or rebuilt from the log.
Each document session uses a bounded input queue. The service limits operations per user and document, pending bytes per connection, and queue length.
If a limit is reached, the service returns a retry response such as 429. Clients that cannot receive updates fast enough may be slowed or disconnected.
These limits stop one busy document or slow client from hurting the whole system.
Presence and cursor updates go to the Presence Store. This data is temporary and expires when heartbeats stop. It is not written to the permanent Operation Log.
Comments are saved in the Operational Store. They use their own IDs and timestamps. They do not use the document edit sequence.
After a comment is saved, it is broadcast to connected clients. Mentions can create notifications in the background.
Search indexing, notifications, audit logs, and analytics also run in the background. Their failure does not block the edit acknowledgement or live broadcast.
A reconnecting client sends document_id, last_applied_sequence, and pending operation IDs. The server sends all missed operations after that sequence.
The client applies those operations first. Its offline edits are then transformed against the newer server edits and sent again.
The Snapshot Store creates snapshots from committed operations. Every snapshot stores snapshot_sequence, which is the last operation included. Recovery loads the snapshot and then applies later operations.
If a Session Owner fails, a new owner reads the last committed sequence from the Operation Log and takes over with a higher epoch. Uncommitted client edits may need to be resent. WebSocket nodes keep temporary connection state, but permanent document data stays in the log and stores.
The benefit is that every document has one clear edit order. The Operation Log keeps edits safe before users see them. The downside is that one Session Owner must handle all edits for one document, so very active documents can become hot. OT keeps edits consistent, but it adds transform work. Bounded queues and connection limits protect the system, but some clients may receive a retry response. Snapshots make loading faster, while background indexing and analytics may appear later.
The interviewer wants to see whether the candidate can handle real-time ordering, duplicate edits, reconnects, offline work, and safe failover. They also want to test WebSocket scaling, durable logs, snapshots, comments, presence, and conflict handling. A strong answer explains both the normal edit path and how the system recovers after a client or server failure.










