📝 Google Docs Real-Time Collaboration Service
Enabling Seamless Multi-User Document Editing
Project Overview
Enabling Seamless Multi-User Document Editing
The Real-Time Collaboration Service (RTCS) is a core component of the Google Docs Microservices Architecture, responsible for enabling multi-user document editing while maintaining data consistency, synchronization, and version control.
The RTCS relies on efficient polling, allows clients to fetch only the latest changes since their last known version. This scalable approach ensures real-time collaboration while reducing bandwidth and system load.
By tracking operations instead of full document states, the RTCS efficiently merges concurrent edits, resolves conflicts, and ensures that all users editing a document eventually see the same version. 🚀
This service relies on the previous google docs microservices we saw:
Identity Access Management API I → Registers and authenticates users, validates authentication tokens. Google Document Management Service -> Handles documents and creations.
Make sure to read the google docs microservices project architecture before starting this service.
Your submissions
No submissions yet, start by making your first submission
Detailed Project Description
The Real-Time Collaboration Service (RTCS) enables simultaneous document editing by multiple users. It ensures synchronization, conflict resolution, and consistency across all users editing the same document. Instead of using WebSockets, it relies on efficient polling where clients fetch the latest changes in batches.
This microservice handles incoming edit operations, applies them sequentially, and ensures that clients stay synchronized by providing a version-based operation history.
This service relies on the previous google docs microservice we saw:
Identity Access Management API I (http://localhost:3033)
→ Registers and authenticates users, validates authentication tokens.
Google Document Management Service (http://localhost:3033)
-> Handles documents and creations.
When your submission is executed, it will have access to a correct implementation of these services running on their respective ports. Your task is to implement the Google Docs Real Time Collaboration Service so that it properly interacts with these services.
Make sure your api runs on the port 3035.
Core Responsibilities
- Accept & process edits submitted by users.
- Track document versions to prevent conflicts.
- Resolve conflicting edits using operational transformation or a last-write-wins approach.
- Serve incremental updates to clients requesting new operations since their last known version.
- Ensure authorization by validating JWTs from the IAM API.
- Persist changes to maintain consistency between the collaboration layer and the Document Management Service.
Key Concepts for Implementation
1. Document Versioning
- Each document has a version number that increments with every change.
- Clients send their last known version when requesting updates, allowing them to fetch only new changes.
- The system ensures eventual consistency, meaning all users will eventually see the same document state.
2. Edit Operations Format
- Edits are stored as operations (insert, delete, update) rather than full document snapshots.
- This enables efficient conflict resolution and bandwidth savings.
3. Conflict Resolution
- Operations are applied sequentially in the order they arrive.
- If two users edit the same part simultaneously, a last-write-wins approach can be used.
- A more advanced operational transformation (OT) mechanism can be added to intelligently merge concurrent edits.
4. Efficient Polling for Updates
- Instead of clients fetching the entire document repeatedly, they request new operations since their last version.
- This minimizes bandwidth usage and improves scalability compared to full document re-fetching.
Service API Endpoints
Make sure your api runs on the port 3035.
1. Submit an Edit Operation
POST /collaboration/{documentId}/operations
Description: Submits a new edit operation for a document.
- The service applies the edit, updates the document version, and stores the operation.
Input:
{ "headers": { "Authorization": "Bearer JWT token", "Content-Type": "application/json" }, "pathParameters": { "documentId": "string" }, "body": { "operationId": "string (UUID)", "timestamp": "string (ISO 8601)", "userId": "string", "operations": [ { "type": "string (insert | delete | update)", "position": "number", "content": "string (optional)" } ] } }
Output:
{ "status": 200, "body": { "message": "Operation accepted", "version": "number" } }
2. Fetch Latest Operations
GET /collaboration/{documentId}/operations?since={version}
Description: Fetches all new operations for a document since a given version.
- This allows clients to stay up-to-date without needing to reload the entire document.
Input:
{ "headers": { "Authorization": "Bearer JWT token" }, "pathParameters": { "documentId": "string" }, "queryParameters": { "since": "number (last known version)" } }
Output:
{ "status": 200, "body": { "operations": [ { "operationId": "string", "userId": "string", "timestamp": "string", "operations": [ { "type": "string (insert | delete | update)", "position": "number", "content": "string (optional)" } ] } ], "latestVersion": "number" } }
Implementation Details
1. Handling Incoming Edits
- Validate the JWT (via IAM API) to ensure the user is authorized.
- Check if the document exists and load its current state.
- Apply the edit operation to the document’s state.
- Store the operation and increment the document’s version.
- Return the updated version to the client.
2. Serving Incremental Updates
- Validate the JWT and the document’s existence.
- Fetch all operations that occurred after the requested
since
version. - Return the list of operations and the latest document version.
- The client applies these operations locally to update their view.
Security Considerations
âś… JWT validation ensures only authenticated users can edit documents.
âś… Rate limiting prevents excessive edit requests per second.
âś… Document ownership checks prevent unauthorized modifications.
âś… Operation history storage enables audit logs and version rollbacks.
How This Service Interacts with Other Microservices
- IAM API → Validates user authentication before processing requests.
- Document Management Service → Fetches document metadata and persists the final document state.
Make sure your api runs on the port 3035.
Conclusion
The Real-Time Collaboration Service (RTCS) is a scalable, efficient, and conflict-resilient solution for handling collaborative document editing. By processing atomic edit operations, tracking versions, and serving incremental updates, it enables seamless synchronization without relying on WebSockets.
Project Completion Criteria
- The system should require a valid JWT token in the `Authorization` header for all requests.
- The system should validate JWT tokens by calling the IAM Service’s `/auth/validate` endpoint before granting access to any resource.
- The system should return a `401 Unauthorized` response for requests with missing, invalid, or expired JWT tokens.
- The system should allow users to submit edit operations via the `POST /collaboration/{documentId}/operations` endpoint.
- The system should apply edit operations sequentially to maintain consistency.
- The system should update the document’s version number with each successful edit operation.
- The system should reject duplicate edit operations (same `operationId`) with a `409 Conflict` response.
- The system should handle concurrent edit operations by applying them in the order they are received.
- The system should support a **last-write-wins** approach for conflicting edits on the same position.
- The system should allow multiple users to edit different parts of a document concurrently without conflicts.
- The system should ensure that all users editing a document eventually see the same final version.
- The system should track and maintain a version number for each document.
- The system should allow clients to fetch only new operations since their last known version via `GET /collaboration/{documentId}/operations?since={version}`.
- The system should return a `404 Not Found` response if a user requests operations for a document that does not exist.
- The system should reject edit operations with an outdated `baseVersion` to prevent inconsistencies.
- The system should return the latest version number after processing each edit operation.
- The system should send updated document content to the DMS via `PUT /documents/{documentId}` after each successful edit operation.