Multi-user scenario like Google Docs

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-03-10

Problem Statement

Design a Google Docs-like system where multiple users can simultaneously edit a document, view real-time updates, and maintain version consistency. Focus is on OOP design, concurrency, collaboration, and modularity.


Functional Requirements


1.Document Management
•Create, delete, and rename documents.
•Each document contains text and optionally images or tables.
2.Multi-User Editing
•Multiple users can edit the same document simultaneously.
•Changes should be visible in real-time to all collaborators.
3.Versioning & History
•Maintain versions of documents for undo/redo or rollback.
•Track user actions for audit and conflict resolution.
4.Change Propagation
•Efficiently propagate changes to all users using events (e.g., via WebSockets or SSE).
•Handle network latency and partial updates.
5.Optional Features
•Commenting and suggesting edits.
•Access control: read-only, edit, or admin permissions.
•Offline edits and synchronization when reconnecting.


Non-Functional Requirements


•Concurrency: Handle simultaneous edits and ensure consistency.
•Low Latency: Reflect changes to all users in real-time.
•Scalability: Support hundreds of concurrent users per document.
•Extensibility: Easy to add new document types or collaboration features.


Edge Cases & Constraints


•Conflicting edits → need conflict resolution strategies (e.g., Operational Transformation or CRDT).
•Network disconnects → handle offline edits and resync when user reconnects.
•Large documents → efficient memory and update propagation.
•Undo/Redo in multi-user context → maintain per-user action stacks.


Design Hints


•Key Classes / Interfaces:
•Document → stores content, metadata, and versions.
•User → represents an editor with permissions.
•Operation → encapsulates a change (insert, delete, format) for OT/CRDT.
•CollaborationManager → handles concurrent edits and conflict resolution.
•EventNotifier → propagates updates to all subscribed users.
•VersionControl → manages undo/redo and document history.
•Data Structures:
•LinkedList / GapBuffer / Rope → for efficient text modifications.
•Queue of Operations → for sequential processing of edits.
•Map<UserId, Session> → track active editors per document.
•Design Patterns:
•Observer Pattern → notify all users of changes in real-time.
•Command Pattern → represent operations for undo/redo.
•Strategy Pattern → pluggable conflict resolution (OT, CRDT).
•Singleton (Optional) → centralized collaboration manager per document.


Example Flow


1.User A inserts "Hello" at position 0 → Operation created.
2.CollaborationManager applies operation to document → updates internal state.
3.EventNotifier pushes update to User B and C in real-time.
4.User B concurrently inserts "World" at position 5 → operations resolved via OT/CRDT.
5.Document state synchronized across all users.


Evaluation Areas


•Clean OOP modeling of documents, users, and operations.
•Efficient real-time update propagation and conflict resolution.
•Extensibility to support additional document types, offline edits, and permissions.
•Handling concurrency and edge cases for multi-user collaboration.


This LLD problem tests OOP design, concurrency handling, real-time collaboration, and event-driven architecture suitable for building a Google Docs-like system.

Solution

Comments