"How would you implement real-time collaborative document editing for Lark (飞书), ensuring consistency when hundreds of users edit simultaneously?"
Lark is ByteDance's flagship enterprise product competing with Google Workspace and Microsoft 365. Real-time collaboration is its core differentiator. This question tests your knowledge of distributed systems fundamentals — conflict resolution, eventual consistency, and latency optimization — in a product context ByteDance cares deeply about.
Compare OT (Operational Transformation) vs. CRDT (Conflict-free Replicated Data Types) and explain why CRDTs are increasingly preferred for their simpler conflict resolution guarantees.
Describe the document model: a tree of blocks (paragraphs, tables, images), each node containing a CRDT-based text sequence.
Explain the sync protocol: local edits applied immediately, sent to server via WebSocket, server merges and broadcasts to other clients.
Address practical concerns: undo/redo with CRDT, cursor/selection awareness, offline editing and reconnection sync.
I would use a CRDT-based approach, specifically a variant of Yjs or a custom RGA (Replicated Growable Array) for text sequences. Each character gets a unique ID composed of a client ID and a logical clock, ensuring deterministic merge ordering without a central authority. The document is modeled as a tree of CRDT nodes — each paragraph is an RGA, tables are CRDT maps of cell references, and rich-text formatting uses a mark-based approach where formatting spans are intervals attached to character IDs. For the sync layer, clients connect via WebSocket to a collaboration server. Local edits are applied optimistically to the client state and sent as delta operations. The server merges incoming deltas using the CRDT merge function and broadcasts the merged state to all connected clients. For offline support, clients accumulate local operations and sync on reconnection — the CRDT guarantees convergence regardless of operation ordering. Awareness features like cursor positions and selections are broadcast separately via a lightweight presence channel with 100ms throttling to reduce network overhead.
Know the difference between OT and CRDT — OT requires a central server for transformation, while CRDTs can merge independently.
Mention Yjs or Automerge as real-world CRDT libraries to show practical awareness.
Discuss the memory overhead of CRDTs (tombstones for deleted characters) and garbage collection strategies.
CRDTs guarantee convergence by construction — any ordering of operations produces the same final state. OT requires a central server to transform operations, creating a single point of failure and making offline editing harder to implement.
Cursors are represented as relative positions between two character IDs rather than absolute offsets. This way, when other users insert or delete text, the cursor position remains semantically correct without explicit transformation.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free