System DesignAdvancedcase study

System Design: Designing a Collaborative Editor (Google Docs)

How does Google Docs handle real-time simultaneous edits? A technical deep dive into Operational Transformation (OT) and Conflict-free Replicated Data Types (CRDTs).

Sachin SarawgiApril 20, 20263 min read3 minute lesson

Key Takeaways

What to remember from this case study

Real-time Collaboration: Multiple users can edit the same document at the same time.

Recommended Prerequisites
System Design: Designing a Distributed Task Scheduler

System Design: Designing a Collaborative Editor (Google Docs)

Designing a collaborative editor like Google Docs or Notion is one of the most technically challenging system design problems. It requires synchronizing the state of a document across multiple users in real-time, even when they are editing the same sentence simultaneously.

1. Core Requirements

  • Real-time Collaboration: Multiple users can edit the same document at the same time.
  • Low Latency: Changes from one user should appear on others' screens in milliseconds.
  • Consistency: Everyone must eventually see the same final document state.
  • Offline Support: Users should be able to edit while offline and sync later.

2. The Conflict Problem

If User A and User B both have a document with "Hello" and they both type a character at the same time:

  • User A types "!" after "o" -> "Hello!"
  • User B types " " after "o" -> "Hello "
  • A simple "Last Write Wins" would lose one of the characters. We need a way to merge these operations.

3. Solution A: Operational Transformation (OT)

OT is the classic solution used by Google Docs and Etherpad.

  • The Concept: Instead of sending the full text, you send "Operations" (Insert, Delete, Retain).
  • Transformation: When the server receives an operation that conflicts with another already processed operation, it "transforms" the new operation to account for the previous change.
  • Pros: Mature, works well for text.
  • Cons: Extremely complex to implement correctly (especially the "Transformation" logic); requires a central server to order operations.

4. Solution B: CRDT (Conflict-free Replicated Data Types)

CRDT is the modern approach used by Notion, Figma, and Automerge.

  • The Concept: Data structures are designed so that any two nodes can merge their state without a central coordinator and always reach the same result.
  • Fractional Indexing: Every character is assigned a unique, immutable ID (e.g., a number between 0 and 1). To insert between "A" (0.5) and "B" (0.6), you assign the new character "C" the ID 0.55.
  • Pros: Decentralized (supports P2P/WebRTC); naturally handles offline-to-online sync; mathematically guaranteed consistency.
  • Cons: High memory overhead (every character needs metadata).

5. High-Level Architecture

  • WebSockets: To push operations to the server and other clients with low latency.
  • Document Service: Manages the active editing sessions and the OT/CRDT logic.
  • Relational DB (Postgres): Stores document metadata and permissions.
  • BLOB Store (S3): Stores the full document snapshots for fast loading.

6. Real-time Awareness (Presence)

  • Cursors: Showing where other users are typing.
  • User List: Who is currently viewing the doc.
  • Implementation: Use a fast in-memory store like Redis with a short TTL for cursor positions.

Summary

Building a collaborative editor is a battle of State Synchronization. While OT is efficient but complex, CRDT is the future of decentralized, offline-first collaboration. By mastering these two algorithms, you can build systems that make the world feel like it's working on a single shared screen.

📚

Recommended Resources

Designing Data-Intensive ApplicationsBest Seller

The definitive guide to building scalable, reliable distributed systems by Martin Kleppmann.

View on Amazon
Kafka: The Definitive GuideEditor's Pick

Real-time data and stream processing by Confluent engineers.

View on Amazon
Apache Kafka Series on Udemy

Hands-on Kafka course covering producers, consumers, Kafka Streams, and Connect.

View Course

Practical engineering notes

Get the next backend guide in your inbox

One useful note when a new deep dive is published: system design tradeoffs, Java production lessons, Kafka debugging, database patterns, and AI infrastructure.

No spam. Just practical notes you can use at work.

Sachin Sarawgi

Written by

Sachin Sarawgi

Engineering Manager and backend engineer with 10+ years building distributed systems across fintech, enterprise SaaS, and startups. CodeSprintPro is where I write practical guides on system design, Java, Kafka, databases, AI infrastructure, and production reliability.

Keep Learning

Move through the archive without losing the thread.

Related Articles

More deep dives chosen from shared tags, category overlap, and reading difficulty.

System DesignAdvanced

System Design: Designing Nearby Friends (Real-time Geospatial Streams)

System Design: Designing Nearby Friends (Real-time Geospatial) Designing a "Nearby Friends" feature (like Snapchat's Snap Map or Facebook's Nearby Friends) is a unique challenge. Unlike Yelp or Uber, where the entities (…

Apr 20, 20263 min read
Deep Dive
#system-design#geospatial#real-time
System DesignAdvanced

System Design: Designing an Online Auction System (eBay Scale)

System Design: Designing an Online Auction System Designing a high-scale auction system like eBay or a penny auction site is a classic concurrency challenge. The system must handle thousands of users bidding on the same…

Apr 20, 20263 min read
Deep Dive
#system-design#auction-system#ebay
System DesignAdvanced

System Design: Designing WhatsApp (Real-time Messaging)

System Design: Designing WhatsApp (Real-time Messaging) Building a chat application like WhatsApp or Facebook Messenger requires managing millions of persistent connections and ensuring that messages are delivered reliab…

Apr 20, 20263 min read
Deep Dive
#system-design#whatsapp#real-time-chat
System DesignAdvanced

System Design: Designing a Video Conferencing System (Zoom / MS Teams)

System Design: Designing a Video Conferencing System Designing a real-time video conferencing system like Zoom or Microsoft Teams is fundamentally different from a video streaming service like YouTube. While YouTube prio…

Apr 20, 20263 min read
Deep Dive
#system-design#webrtc#video-conferencing

More in System Design

Category-based suggestions if you want to stay in the same domain.