Back to LLD explorer
Concurrency / Realtime Patterns: Command, Observer

Google Docs

Hard

Problem Summary

Design a collaborative real-time document editor class system managing operational transforms and cursor syncing.

Functional Scope

  • Support concurrent text edits from multiple user connections.
  • Resolve edit conflicts using Operational Transformation (OT) or Conflict-free Replicated Data Types (CRDT).
  • Broadcast updates to active participants dynamically.

Entity-Relationship (ER) Schema

Document [1] <---> [*] TextOperation
Document [1] <---> [*] UserSession

Design Approach

Maintain absolute index offsets on operations. Transform indices on concurrent inserts using standard client-server sequence IDs to maintain convergence.

Core Classes & Models

Document (Character list, version history)Operation (Insert/Delete character, Position, Version)OTEngine (Transforms operations so they execute consistently)UserSession (Tracks connection socket and cursor position)
Code Blueprint
public class TextOperation {
    private int position;
    public synchronized void transform(TextOperation concurrentOp) {}
}