Collaborative Document Repository

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-05-30

Problem Statement

Design the Low-Level Design (LLD) for a Collaborative Document Repository, similar to Google Docs, Confluence, or Notion, where users can create, edit, share, and collaborate on documents in real-time.


The system should support versioning, concurrent edits, access control, and searchability of documents, while ensuring data consistency and collaboration-friendly architecture.


🎯 Core Requirements


1. Document Management


•Users should be able to:
•Create new documents.
•Edit and save document content.
•Maintain document versions for rollback.
•View or delete documents they own or have access to.


2. Collaboration


•Multiple users can edit the same document concurrently.
•System should manage:
•Conflict resolution.
•Real-time updates (using events, change diffs, or operational transforms).
•Locking or merging of content where needed.


3. Access Control


•Each document can be:
•Private (only owner can view/edit).
•Shared (specific users with view/edit permissions).
•Public (anyone with link can view).
•System should support granular permissions:
•READ, WRITE, COMMENT, OWNER.


4. Versioning & History


•Each save or edit creates a new version of the document.
•A user should be able to:
•View the change history.
•Restore an older version.


5. Search


•Users should be able to search documents by:
•Title, tags, owner, or content.


6. Optional Enhancements


•Real-time presence indicator (who’s editing).
•Commenting or suggestion mode.
•Offline editing + sync later.


⚙️ Functional APIs


OperationDescription


createDocument(userId, title, content)


Creates a new document and assigns ownership.


editDocument(documentId, userId, changes)


Edits document if user has permission.


getDocument(documentId, userId)


Retrieves the latest version of the document.


shareDocument(documentId, targetUserId, permission)


Grants access to another user.


listDocuments(userId)


Lists all documents owned or shared with user.


getVersionHistory(documentId)


Fetches all previous versions of a document.


restoreVersion(documentId, versionId)


Restores content to a specific version.


🧱 Suggested Class Design


ClassResponsibility


Document

Represents a document with metadata, current content, and versions.


DocumentVersion

Stores versioned content with timestamp and author.


User

Represents a system user with name, email, and role.


Permission

Defines access levels (read/write/comment).


CollaborationSession

Manages real-time edits for concurrent users.


DocumentRepository

Handles storage, retrieval, and version persistence.


VersionManager

Manages version creation, retrieval, and rollback.


AccessControlManager

Manages document sharing and permission validation.


SearchService

Provides text and metadata search capabilities.


🧩 Example Entity


Document

1 2documentId: "doc-1234" 3title: "Project Plan" 4ownerId: "user-001" 5content: "Initial content..." 6createdAt: 2025-10-24 7lastModifiedAt: 2025-10-24 8versions: [v1, v2, v3] 9permissions: { 10 "user-002": WRITE, 11 "user-003": READ 12}


DocumentVersion

1 2versionId: v2 3content: "Updated project plan with new timeline" 4modifiedBy: "user-002" 5timestamp: 2025-10-24T14:10:00Z


🧠 Design Considerations


Concurrency Management:

•Implement a locking mechanism or Operational Transformation (OT) / Conflict-free Replicated Data Type (CRDT).
•Avoid data loss during concurrent edits.

Versioning:

•Use delta-based storage for efficiency.
•Maintain snapshot at intervals.

Permissions:

•Enforce access rules before each operation.
•Maintain audit logs for changes.

Scalability:

•Use distributed document storage.
•Cache frequently accessed documents.


🔄 Example Flow


1. Document Creation

1 2User A → createDocument("Project Plan") 3System → Creates Document (doc-1234) with A as owner


2. Collaboration

1 2User A shares with User B (WRITE access) 3Both edit doc-1234 concurrently 4System merges changes and updates version history


3. Versioning

1 2User B saves changes → New version (v3) created 3User A restores version v2 if needed


4. Access Control

1 2User C (no permission) tries to access doc-1234 → Access Denied


🧱 Sample Class Diagram (Conceptual)

1 2+--------------------+ 3| Document | 4+--------------------+ 5| documentId | 6| title | 7| content | 8| ownerId | 9| versions[] | 10| permissions{} | 11+--------------------+ 12 13+--------------------+ 14| DocumentVersion | 15+--------------------+ 16| versionId | 17| content | 18| modifiedBy | 19| timestamp | 20+--------------------+ 21 22+--------------------+ 23| AccessControlMgr | 24+--------------------+ 25| +grantAccess() | 26| +validateAccess() | 27+--------------------+ 28 29+--------------------+ 30| VersionManager | 31+--------------------+ 32| +saveVersion() | 33| +restoreVersion() | 34+--------------------+ 35 36+--------------------+ 37| CollaborationSession| 38+--------------------+ 39| +handleEditEvents()| 40| +broadcastChanges()| 41+--------------------+


🚀 Possible Extensions


•Add real-time WebSocket-based updates.
•Support comments and annotations.
•Integrate document templates.
•Add file attachments to documents.
•Include audit trail (who edited what and when).
•Integrate with external storage (e.g., S3, GCS).


✅ Goal:


Design an extensible, object-oriented Collaborative Document Repository that supports multi-user editing, versioning, permissions, and real-time collaboration — with a focus on modularity, scalability, and consistency.

Solution

Comments