Google Docs Microservices Architecture
Google Docs Microservices Architecture
Last updated: 3/16/2025
Google Docs Microservices Architecture
This project implements a Google Docs-style collaborative document editing system using a microservices architecture. It consists of multiple independent services that work together to provide authentication, document management, and real-time collaboration.
Microservices Overview
The project consists of three core microservices:
-
Identity Access Management API (IAM API)
- Provides authentication and authorization via JWT tokens.
- Manages user registration, login, and token validation.
- Ensures that only authenticated users can access protected resources.
-
Document Management Service (DMS)
- Stores, retrieves, and updates document contents.
- Acts as the source of truth for documents.
- Ensures secure document access and persistence.
- Integrates with IAM API for authentication.
-
Real-Time Collaboration Service (RTCS)
- Handles multi-user document editing with efficient version tracking.
- Applies edit operations sequentially and resolves conflicts.
- Provides incremental updates so clients only fetch the latest changes.
- Integrates with DMS to persist changes.
How the Microservices Work Together
1. Authentication & Authorization
- Users register and log in via the IAM API (
http://localhost:3033
). - The IAM API issues a JWT token, which users include in the
Authorization
header. - All microservices validate the JWT by calling the IAM API’s
/auth/validate
endpoint before processing requests.
2. Document Management
- Users create, update, and retrieve documents via the DMS (
http://localhost:3034
). - Each document has a unique ID and is stored securely.
- The DMS validates JWTs before granting access.
3. Real-Time Collaboration
- The RTCS (
http://localhost:3035
) enables multi-user editing. - Users submit edit operations (
insert
,delete
,update
) to the RTCS. - The RTCS tracks document versions, applies edits, and stores operation history.
- Clients poll the RTCS to fetch the latest changes since their last known version.
- Once edits are finalized, the RTCS updates the DMS to persist changes.
API Endpoints Overview
1. Identity Access Management API (IAM)
POST /auth/register
→ Register a new user.POST /auth/login
→ Authenticate user and return a JWT.POST /auth/logout
→ Invalidate JWT.POST /auth/validate
→ Validate JWT for other services.
2. Document Management Service (DMS)
GET /documents
→ List all documents for a user.POST /documents
→ Create a new document.GET /documents/{documentId}
→ Retrieve a document.PUT /documents/{documentId}
→ Update document content.DELETE /documents/{documentId}
→ Delete a document.
3. Real-Time Collaboration Service (RTCS)
POST /collaboration/{documentId}/operations
→ Submit an edit operation.GET /collaboration/{documentId}/operations?since={version}
→ Fetch operations since a specific version.
Key Features and Design Principles
✅ Scalable Microservices Architecture
- Each service is independent and stateless, allowing horizontal scaling.
- Services communicate via HTTP requests.
- JWT-based stateless authentication ensures low overhead.
🔄 Efficient Real-Time Collaboration
- Instead of sending the full document, RTCS only transmits incremental changes.
- Clients fetch only new operations since their last known version.
- Conflict resolution mechanisms ensure data consistency.
🔒 Security and Access Control
- All requests require JWT authentication via the IAM API.
- The DMS enforces ownership checks, preventing unauthorized access.
- Rate limiting prevents abuse of the RTCS API.
🔗 Seamless Service Integration
- The IAM API validates users for both the DMS and RTCS.
- The RTCS ensures synchronization while the DMS stores the final document state.
- Clients interact seamlessly with all three services.
Running the Project
Once you have implemented the 3 services for this project, you can visualize them in action by downloading this nextjs frontend project and running it and it will communicate with your services. (make sure to enable cors on your services to allow your browser to send requests to them).
1. Start the Backend Services
Run each microservice in a separate terminal:
# Start IAM API (Authentication Service) pnpm run start:iam # Start Document Management Service (DMS) pnpm run start:dms # Start Real-Time Collaboration Service (RTCS) pnpm run start:rtcs
2. Start the Frontend
Once the backend services are running, start the frontend:
pnpm install pnpm dev
The frontend will connect to the backend and allow users to:
- Register/Login
- Create and edit documents
- See real-time updates from multiple users
Conclusion
This project demonstrates a fully functional, distributed Google Docs-style system using a modern microservices architecture.
By separating concerns into distinct services, the system is scalable, efficient, and secure.
Each microservice plays a crucial role:
- Google Docs Identity Access Management API handles authentication.
- Google Docs Document Management Service ensures secure storage.
- Google Docs Real-Time Collaboration Service enables real-time collaboration.
With this modular architecture, the system can easily scale to support thousands of concurrent users. 🚀