Bird
Raised Fist0

Design Google Docs - Collaborative Editing, Conflict Resolution, OT vs CRDT

HLDhardInterview freq: high
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/6
API Gateway

Receives user edit via WebSocket

User Alice sends an edit operation to the document

Protocol:WebSocket
BeforeAlice's edit exists only on her client device
AfterEdit received by API Gateway, ready for routing
Edit Router

Routes edit to OT or CRDT service

Determines document uses OT; forwards edit to OT Service

Protocol:Internal RPC
BeforeEdit queued at Edit Router, undecided processing path
AfterEdit forwarded to OT Service for transformation
Operational Transf. (OT) Service

Transforms edit against concurrent operations

Applies OT algorithm to maintain consistency

Protocol:Internal RPC
BeforeEdit untransformed, concurrent edits unknown
AfterEdit transformed and conflict minimized
Conflict Resolver

Merges transformed edit with document state

Resolves any remaining conflicts before storage

Protocol:Internal RPC
BeforeTransformed edit ready for merge
AfterMerged edit ready to be persisted
Storage Layer

Persists merged edit and updates document state

Stores new document version and edit history

Protocol:Internal RPC
BeforeMerged edit not yet stored
AfterDocument state updated and durable
Notification Service

Sends update notifications to collaborators

Notifies other users of document changes

Protocol:Internal RPC
BeforeCollaborators unaware of new edit
AfterCollaborators receive real-time update alerts
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────┐
│  API Gateway  │
└───────┬───────┘
        │ WebSocket
        ▼
┌───────────────┐
│  Edit Router  │
└───────┬───────┘
        │ Internal RPC
        ▼
┌───────────────────────────────┐
│ Operational Transf. (OT)      │
│          Service              │
└───────┬───────────────────────┘
        │ Internal RPC
        ▼
┌───────────────┐
│Conflict Resolver│
└───────┬───────┘
        │ Internal RPC
        ▼
┌───────────────┐
│ Storage Layer │
└───────┬───────┘
        │ Internal RPC
        ▼
┌───────────────┐
│Notification   │
│Service        │
└───────────────┘
        ▲
        │ Internal RPC
        │
┌───────────────┐
│  CRDT Service │
└───────────────┘
        ▲
        │ Internal RPC
        │
        └───────────────►

This architecture supports real-time collaborative editing by routing user edits through an API Gateway to an Edit Router, which selects either the OT or CRDT service based on document type. The OT Service applies operational transformation algorithms to handle concurrent edits, while the CRDT Service manages conflict-free replicated data types. The Conflict Resolver merges transformed edits to ensure consistency before persisting changes in the Storage Layer. Finally, the Notification Service pushes updates to collaborators, enabling seamless real-time collaboration. This vertical flow ensures edits are consistently transformed, merged, stored, and broadcasted, balancing low latency with strong consistency guarantees.

Primary Focus

✓

Practice

(1/5)
1. In the request flow, at Step 4 the Cache Node receives a key lookup request. What happens if the key is not found in the local cache at this step?
easy
A. The Cache Node immediately returns a cache miss to the client
B. The Cache Node forwards the request to the next node in the consistent hash ring
C. The Cache Node broadcasts the request to all cache nodes to find the key
D. The Cache Node fetches the value from the backing data store and updates its cache

Solution

  1. Step 1: Trace cache miss handling at Step 4

    On a miss, the node does not return immediately; it attempts to find the key elsewhere.
  2. Step 2: Broadcast vs forwarding

    Forwarding to next node breaks consistent hashing guarantees; fetching from backing store happens after confirming absence in cache cluster.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Cache node broadcasts to find key before fallback [check]
Hint: Cache miss triggers broadcast to find key in cluster [OK]
Common Mistakes:
2. A recommendation system must handle 10,000 user rating updates per second and asynchronously update user embeddings without blocking user requests. Which component best handles this decoupling?
easy
A. Use a batch job that runs once per hour to update embeddings
B. Use an in-memory cache like Redis to store embeddings and update synchronously
C. Use a message queue like Kafka to buffer rating events for asynchronous processing
D. Use a relational database with synchronous writes for embedding updates

Solution

  1. Step 1: Identify decoupling need

    High write rate (10,000/sec) requires asynchronous processing to avoid blocking user requests.
  2. Step 2: Evaluate components

    Relational DB synchronous writes (A) block requests; Redis (B) lacks durability guarantees for event buffering; batch jobs (C) are too infrequent for real-time updates. Kafka (D) buffers events reliably and supports asynchronous consumption.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Kafka buffers high write throughput asynchronously [check]
Hint: Buffer high writes asynchronously with Kafka [check]
Common Mistakes:
3. In a system where a cache is checked before querying the database, at Step 3 the Cache Layer receives a read request. What happens if the cache misses at this step?
easy
A. The Cache Layer forwards the request to the Database and waits for the response
B. The Cache Layer returns a null response immediately to the client
C. The Cache Layer retries the cache read multiple times before failing
D. The Cache Layer writes a placeholder value to the cache and returns it

Solution

  1. Step 1: Trace Cache Layer behavior on miss

    On a cache miss, the Cache Layer must fetch data from the Database to serve the request.
  2. Step 2: Understand why other options fail

    Returning null or placeholders breaks correctness; retrying cache reads wastes time without new data.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Cache miss triggers DB fetch before responding [check]
Hint: Cache miss -> fetch from DB before reply [check]
Common Mistakes:
4. For a distributed key-value store that must handle frequent node additions and removals with minimal key remapping, which approach is best?
medium
A. Use modular hashing with a fixed bucket count and rehash keys on node changes
B. Use a centralized directory service mapping keys to nodes updated on every node change
C. Use consistent hashing with virtual nodes to balance load and minimize remapping
D. Use rendezvous hashing to assign keys to nodes without a ring structure

Solution

  1. Step 1: Compare modular hashing and consistent hashing

    Modular hashing requires full remapping on node changes, causing high overhead.
  2. Step 2: Evaluate alternatives

    Centralized directory adds latency and single point of failure; rendezvous hashing is good but less common and more complex than consistent hashing with virtual nodes.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Consistent hashing with virtual nodes balances load and minimizes remapping [check]
Hint: Virtual nodes smooth load, minimize remap on node changes [check]
Common Mistakes:
5. At 10x scale, which component in a synchronous chat system is most likely to fail first and why?
hard
A. The database, because it cannot handle the increased write volume synchronously
B. The load balancer, because it cannot distribute synchronous requests evenly at high scale
C. The client devices, because they cannot maintain multiple synchronous connections simultaneously
D. The chat servers, because WebSocket connections are stateful and cannot be easily resharded or migrated

Solution

  1. Step 1: Identify stateful bottleneck in synchronous chat

    Chat servers maintain WebSocket connections statefully, binding clients to specific servers.
  2. Step 2: Analyze scaling challenges

    At 10x scale, resharding or migrating these stateful connections is complex, causing chat servers to fail first.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Stateful WebSocket servers limit horizontal scaling, causing early failure [check]
Hint: Stateful WebSocket servers bottleneck synchronous chat scaling [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard