Building Real-Time Collaborative Editors: Architecture, Tradeoffs, and Scale
Introduction
When you watch a colleague's cursor glide across a shared document, see their edits appear letter-by-letter on your screen, and realize your own changes merge seamlessly without overwriting theirs, you're witnessing one of distributed systems' most elegant challenges: real-time collaborative editing at scale.
Building a system like Google Docs or Figma means solving problems that sit at the intersection of distributed computing, networking, and user experience. Research shows that delays exceeding 100ms become noticeable to users, while anything beyond 300ms significantly degrades the collaboration experience. Yet you're orchestrating updates across potentially hundreds of concurrent editors, each generating 1,000 to 10,000 operations per second per active document, all while maintaining data consistency and handling network failures gracefully.
This post explores the technical architecture of real-time collaborative editors, examining the concrete tradeoffs between Operational Transformation and CRDTs, the mechanics of WebSocket fan-out, persistence strategies, and the thorny problem of offline reconciliation. We'll ground every architectural decision in research data and real-world constraints faced by senior engineers building these systems.

Conflict Resolution: Operational Transformation vs CRDTs
The fundamental challenge in collaborative editing is deceptively simple: when two users edit the same document simultaneously, how do you merge their changes without data loss or corruption?
Without proper conflict resolution, research indicates systems can experience data inconsistency rates of 15-30% in concurrent editing scenarios. The two dominant approaches, Operational Transformation and Conflict-Free Replicated Data Types, take radically different philosophical paths to solving this problem.

Operational Transformation: Centralized Coordination
Operational Transformation (OT) treats edits as operations that can be transformed to account for concurrent changes. When User A inserts "hello" at position 5 while User B deletes characters 3-7, OT algorithms transform these operations so they can be applied in any order while converging to the same final state.
The mathematical foundation requires two properties:
C1 (Convergence): All replicas must converge to identical states regardless of operation arrival order.
C2 (Causality Preservation): Operations must maintain their causal relationships, so an operation that depends on another cannot be applied first.
Google Docs uses a variant called Jupiter, which maintains a client-server architecture where the server acts as the single source of truth. Each client maintains its own state and a queue of pending operations. When the client sends an operation to the server, it continues optimistically applying local changes. The server transforms incoming operations against its authoritative state and broadcasts the transformed operations to other clients.
The centralized nature provides clear advantages. The server can enforce permissions, maintain a single operation history, and simplify the transformation logic since operations only need to be transformed against the server state, not against every possible peer state. Research shows this approach works reliably for documents with dozens to hundreds of concurrent editors.
However, OT carries complexity costs. The transformation functions must be carefully designed to maintain the convergence properties. As the number of operation types grows (insert, delete, format, move, paste), the transformation matrix expands. While not growing at an unmanageable rate for typical document operations, the logic requires rigorous testing and formal verification to prevent edge cases that break convergence.
CRDTs: Distributed Consistency
Conflict-Free Replicated Data Types take a fundamentally different approach: design data structures where concurrent operations commute mathematically. If operations can be applied in any order and always produce the same result, you eliminate the need for transformation entirely.
Research indicates CRDTs can reduce server-side conflict resolution overhead by 60-80% compared to OT systems. The server becomes a simple message relay rather than a transformation coordinator. This architectural simplification enables better horizontal scaling and removes the server as a single point of failure for convergence logic.
Figma's multiplayer system uses CRDTs, which aligns well with their canvas-based editing model. Design operations like moving an object, changing a color, or adjusting a layer often have natural commutative properties. The mathematical guarantees of eventual consistency mean the system can tolerate network partitions and still converge once connectivity resumes.
The tradeoff appears in metadata overhead. CRDTs must carry additional information to determine operation ordering and merging. Research shows this typically results in 20-40% larger document sizes compared to plain text representations. For a text document, each character might carry metadata about its unique identifier, creation timestamp, and position in a logical sequence.
Consider a simplified text CRDT where each character insertion generates a unique identifier combining the client ID, a logical timestamp, and position information. This metadata enables deterministic merging but grows the in-memory representation significantly. Production implementations use sophisticated compression techniques to mitigate this overhead, but the fundamental tradeoff remains.
Choosing Your Consistency Model
The OT versus CRDT decision hinges on your specific constraints:
Choose OT when:
- You need a single authoritative version for compliance or auditing
- Server-side permission checks must happen before operations are accepted
- Your operation types have complex interdependencies
- Document size is a critical constraint
Choose CRDTs when:
- Horizontal scaling and fault tolerance are paramount
- Offline-first editing is a core requirement
- Your operations have natural commutative properties
- You can absorb the metadata overhead
Research on distributed systems suggests that the convergence time in well-designed systems of either type typically remains under one second, making both approaches viable for real-time collaboration. The architectural implications beyond conflict resolution often matter more than the resolution mechanism itself.
Presence, Cursors, and Awareness
While document operations handle the "what" of collaboration, presence systems handle the "who" and "where." Seeing your colleague's cursor position, their current selection, and their online status transforms a shared document from a database synchronization problem into a genuinely collaborative experience.
Presence data has different characteristics than document operations. It's ephemeral (a cursor position from five seconds ago is irrelevant), high-frequency (users generate updates continuously as they move their mouse), and lossy (dropping occasional updates doesn't break the experience). These properties allow for different optimization strategies.

Presence Data Architecture
A typical presence update contains 50-100 bytes: user identifier, cursor position (x, y coordinates or text offset), selection range if applicable, and a timestamp. Research suggests update frequencies of 100-300ms intervals balance smoothness with bandwidth consumption.
For a document with 10 active users, each sending updates approximately 5 times per second at 75 bytes per update, you're transmitting roughly 3.75 KB/s per document. This might seem modest, but it scales linearly with user count. A document at Google Docs' official limit of 100 concurrent editors would generate 37.5 KB/s just for presence data, or about 2.25 MB per minute.
The key architectural decision is whether presence data flows through the same channel as document operations. Many production systems separate these concerns:
Shared channel approach: Presence updates and document operations flow through the same WebSocket connection and server infrastructure. This simplifies client logic and ensures consistent ordering, but presence traffic can interfere with critical document operations during congestion.
Separate channel approach: Presence data uses a dedicated WebSocket connection or even UDP for lower latency. This isolates presence traffic but requires clients to maintain multiple connections and handle synchronization between channels.
Research on real-time systems indicates that separating channels provides better tail latencies for document operations, particularly when presence traffic spikes during active collaboration sessions.
Cursor Rendering and Interpolation
Client-side rendering introduces another optimization layer. Rather than rendering every presence update immediately, production systems often interpolate cursor positions between received updates. If you receive cursor positions at 200ms intervals, interpolation can create smooth 60fps animation by predicting intermediate positions based on velocity and direction.
This prediction occasionally produces artifacts when users change direction suddenly, but research shows users tolerate these minor inconsistencies in presence data far more than inconsistencies in document content. The tradeoff between bandwidth and smoothness tilts heavily toward reducing bandwidth for presence systems.
Presence at Scale
When documents approach the upper limits of concurrent editors, presence systems face additional challenges. Research indicates that 50-200 simultaneous editors represents the practical limit for meaningful collaboration, but systems must handle these edge cases gracefully.
Beyond a certain threshold, rendering every user's cursor creates visual clutter that degrades rather than enhances the experience. Production systems often implement viewport-based filtering, only showing cursors for users editing visible portions of the document. For a large document where users work on different sections, this can reduce rendered cursors by an order of magnitude while maintaining awareness of nearby collaborators.
WebSocket Connection Management and Fan-out
Real-time collaboration demands bidirectional, low-latency communication between clients and servers. While HTTP long polling can approximate real-time updates, research shows WebSockets provide 40-60% reduction in bandwidth and 2-3x faster message delivery compared to polling approaches.

Connection Lifecycle and Scaling
Each WebSocket connection maintains persistent TCP state on the server. Research indicates the memory overhead is approximately 1KB per connection, meaning 10,000 concurrent WebSocket connections consume roughly 1GB of RAM just for connection state. This doesn't include application-level buffers, user session data, or document state, which can multiply memory requirements significantly.
Production systems handle this through horizontal scaling. Rather than attempting to handle all connections on a single server, connection servers form a cluster where each server handles a subset of active clients. The challenge then becomes routing messages between clients connected to different servers.
Message Fan-out Architecture
When a user performs an edit, that operation must reach every other collaborator viewing the same document. This fan-out problem has several architectural solutions:
Direct server-to-server: Each connection server maintains awareness of which other servers host clients for each document. When receiving an operation, the server directly notifies peer servers. This minimizes latency but requires full mesh connectivity and careful state management.
Message queue intermediary: Operations flow through a message queue like Redis Pub/Sub, Apache Kafka, or RabbitMQ. Connection servers subscribe to channels for active documents and receive operations through the queue. Research shows Redis Pub/Sub can handle over 100,000 messages per second, while Kafka can process over 1 million messages per second, though with higher latency characteristics.
The message queue approach provides clean separation between operation processing and connection management. A separate set of application servers can handle operation validation, transformation, and persistence, while connection servers focus solely on WebSocket management and fan-out.
Connection Resilience
Network conditions in the real world are messy. Clients switch between WiFi and cellular, pass through tunnels, and contend with congested networks. Production systems must handle these disruptions gracefully.
When a WebSocket connection drops, the client must reconnect and resynchronize its state. The server typically maintains a buffer of recent operations per document. Upon reconnection, the client sends the last operation ID it successfully processed, and the server replays any operations the client missed.
Research on distributed systems suggests that acknowledgment-based protocols provide the reliability needed for zero data loss. Each operation carries a unique ID, clients acknowledge received operations, and servers maintain unacknowledged operations in a retry queue. This adds protocol complexity but provides strong delivery guarantees even in the face of connection instability.
Load Balancing Considerations
Traditional HTTP load balancing distributes requests across servers randomly or using round-robin algorithms. WebSocket connections require different strategies since all operations for a document should ideally flow through the same server to minimize coordination overhead.
Production systems often use consistent hashing based on document ID to route connections. All clients editing document X connect to the same server (or a small set of servers for redundancy). This locality enables efficient in-memory state management and reduces cross-server coordination.
However, this creates potential hotspots. A viral document with thousands of concurrent editors can overwhelm a single server. Systems must detect these hotspots and implement dynamic redistribution, though this adds significant complexity to maintain consistency during migration.
Persistence, Snapshotting, and Compaction
Real-time collaboration happens in memory for performance, but documents must ultimately persist to durable storage. The persistence strategy profoundly impacts both system performance and operational complexity.

Operation Log vs State-Based Persistence
Two fundamental approaches exist for persisting collaborative documents:
Operation log: Store every operation in the order it was applied. The current document state can be reconstructed by replaying all operations from the beginning. This provides complete history and enables time-travel debugging, but document loading time grows linearly with operation count.
State-based: Periodically serialize the full document state to storage. This enables fast loading but loses fine-grained history unless combined with operation logging.
Production systems typically use a hybrid approach. Research suggests taking snapshots every 50-100 operations or at 5-10 minute intervals, whichever comes first. Between snapshots, the system logs individual operations. To load a document, read the most recent snapshot and replay operations since that snapshot.
Snapshot Storage and Compression
Research indicates that the average Google Docs document ranges from 50-200KB, but with full revision history, this can increase 5-10x. Delta compression techniques can achieve 85-95% size reduction by storing only the differences between successive snapshots rather than complete copies.
The storage tier typically follows a hot/cold pattern:
Hot storage: Active documents being edited right now live in memory (Redis or similar). Research suggests targeting a cache hit ratio above 95% for active sessions to maintain performance. For a system with 1 million active documents at 150KB average size, you need approximately 150GB of hot storage capacity.
Warm storage: Recently accessed documents that might be opened again soon live in fast persistent storage (SSDs, managed databases with good read performance).
Cold storage: Archived documents that haven't been accessed in weeks or months can move to cheaper object storage (S3, Cloud Storage).
Compaction Strategies
As documents accumulate thousands or millions of operations over their lifetime, the operation log becomes unwieldy. Compaction periodically rewrites the operation log to remove redundant operations.
Consider a sequence where a user types "hello", deletes it, and types "goodbye". The operation log contains seven operations (five inserts, one delete range, seven more inserts), but the final state could be represented by a single snapshot or seven insert operations. Compaction identifies these patterns and produces a more efficient representation.
Research on distributed systems indicates that compaction should run asynchronously to avoid blocking active editing. Production systems typically trigger compaction when a document becomes inactive or when the operation log exceeds a size threshold. The compacted version becomes the new baseline, and the old operation log can be archived for compliance requirements or deleted if full history isn't needed.
Consistency Guarantees
Persistence introduces consistency challenges. When a client's operation is acknowledged, what guarantees exist about durability? Several levels are possible:
Memory acknowledgment: The operation reached the server's memory and will be applied. If the server crashes before persisting to disk, the operation may be lost.
Disk acknowledgment: The operation was written to persistent storage. It will survive server failures but may not yet be replicated.
Replicated acknowledgment: The operation was persisted to multiple servers in different failure domains. It will survive datacenter-level failures.
The choice impacts latency significantly. Research shows that memory acknowledgment can complete in under 10ms, disk writes add 10-50ms depending on storage technology, and cross-datacenter replication can add 50-200ms depending on geographic distance.
Production systems often tier these guarantees. Critical operations like permission changes might require replicated acknowledgment, while routine edits use memory acknowledgment with asynchronous replication. This balances durability with user experience.
Offline Editing and Reconciliation
The most challenging scenario in collaborative editing is offline operation. When a user loses network connectivity, continues editing, and later reconnects, their changes must merge with potentially conflicting updates from other users who remained online.
Offline-First Architecture
Supporting offline editing requires rethinking the client architecture. Rather than treating the server as the source of truth, the client must maintain its own authoritative state and operation queue.
When online, the client operates in normal collaborative mode: sending operations to the server, receiving operations from other users, and transforming as needed. When the network disconnects, the client continues accepting user input and queuing operations locally. All operations receive unique identifiers that will remain valid when the client reconnects.
The client must also persist its state locally. Browser-based clients typically use IndexedDB, while native applications use SQLite or similar embedded databases. Research suggests that production systems persist both the current document state and the queue of unsynced operations to survive client crashes or browser restarts.
Reconnection and Reconciliation
When connectivity resumes, the client faces a reconciliation problem. While offline, the server state has diverged. Other users may have edited the same sections, deleted content the offline user modified, or restructured the document entirely.
The reconciliation process depends heavily on whether the system uses OT or CRDTs:
CRDT reconciliation: The mathematical properties of CRDTs make this conceptually straightforward. The client sends all operations generated while offline. The server (and other clients) apply these operations using the CRDT merge rules. Because operations commute, the order doesn't matter, and all clients eventually converge to the same state.
In practice, production systems optimize this by sending a compressed representation of offline changes rather than raw operations. If a user typed and deleted extensively while offline, the final state diff may be much smaller than the operation log.
OT reconciliation: Operational Transformation requires more complex reconciliation. The client's offline operations were based on a stale document state. These operations must be transformed against all operations that occurred on the server during the offline period.
The client typically sends its operation queue along with the document version it last synchronized. The server identifies all operations since that version and computes a transformation that rebases the client's operations onto the current state. This transformed operation sequence is then applied to the server state and broadcast to other clients.
Conflict Detection and User Notification
Even with mathematically sound convergence algorithms, offline reconciliation can produce results that surprise users. If User A spent an hour offline restructuring a document while User B deleted half the content, the merged result may satisfy convergence properties but confuse both users.
Production systems often detect significant conflicts and notify users rather than silently merging. Heuristics might include:
- Large sections of text deleted by one user and modified by another
- Structural changes (like reordering sections) that conflict with content edits
- Simultaneous edits to the same sentence or paragraph
When conflicts are detected, the system might present a conflict resolution UI, similar to version control merge tools, allowing users to review changes and choose how to proceed. Research on user experience in collaborative systems suggests that transparency about conflicts improves trust, even if it requires manual intervention.
Offline Storage Limits
Client-side storage is finite, particularly in browser environments. A user who remains offline for days while editing a large document could generate megabytes of operation data. Production systems must handle storage limits gracefully.
Common strategies include:
- Periodic compaction of the offline operation queue, similar to server-side compaction
- Limits on offline operation queue size, with warnings when approaching limits
- Prioritizing recent operations if storage runs out, potentially losing fine-grained history of older offline edits
Research suggests that most offline sessions are short (minutes to hours rather than days), making these edge cases rare in practice. However, robust systems must handle them without data loss.
Production Architecture: Putting It All Together
Having explored individual components, let's examine how they integrate into a complete system architecture that can handle thousands of concurrent documents with hundreds of editors each.

Multi-Tier Server Architecture
Production systems typically separate concerns across specialized server tiers:
Connection servers: Handle WebSocket connections, presence updates, and message fan-out. These servers are stateless regarding document content, making them easy to scale horizontally. Research suggests approximately 10,000 concurrent WebSocket connections per server, meaning a system supporting 1 million concurrent users needs roughly 100 connection servers.
Application servers: Process document operations, apply OT transformations or CRDT merges, enforce permissions, and coordinate persistence. These servers maintain hot document state in memory and interface with the storage tier. They subscribe to message queues for documents they're managing and publish transformed operations back to the queue for fan-out.
Storage tier: Handles persistence, snapshotting, and serving cold documents. This tier typically uses a combination of in-memory caches (Redis), managed databases (PostgreSQL, MongoDB), and object storage (S3) depending on data temperature.
Scaling Patterns
As load increases, different components scale differently:
Connection servers scale approximately linearly with concurrent user count. Each user needs one WebSocket connection, and connection servers are largely stateless, making horizontal scaling straightforward.
Application servers scale with the number of active documents and operation rate. A viral document with intense editing activity might require dedicated application server capacity. Systems must detect hotspots and dynamically allocate resources.
Storage tier scaling depends on access patterns. Read-heavy workloads benefit from caching and read replicas. Write-heavy workloads require careful database tuning and potentially sharding strategies.
Geographic Distribution
For global user bases, latency becomes a critical concern. Research indicates that network round-trip times under 300ms are necessary for acceptable user experience, but cross-continental latencies often exceed this threshold.
Production systems deploy regionally distributed infrastructure. Users connect to nearby connection servers, reducing WebSocket latency. Document state might be mastered in one region but replicated to others, trading slightly stale presence data for better operation latency.
The CAP theorem applies here: during network partitions between regions, systems must choose between availability (allowing edits that might conflict) and consistency (blocking edits until regions can coordinate). Research on distributed systems suggests that collaborative editing systems typically prioritize availability, using eventual consistency models to reconcile conflicts after partition resolution.
Cost Modeling
Understanding the economic implications helps make informed architectural decisions. Based on research estimates of 1,000-5,000 per hour, or $720,000-3,600,000 per month.
This breaks down approximately as:
- Compute: Connection and application servers represent the largest cost component, particularly for WebSocket connections that maintain persistent state.
- Storage: Hot storage in memory caches is expensive per GB but needed for performance. Cold storage in object stores is cheap but requires careful lifecycle management.
- Bandwidth: Real-time synchronization generates significant egress traffic, particularly for presence updates and operation fan-out.
- Operational overhead: Monitoring, logging, and incident response add 15-25% overhead beyond raw infrastructure.
These estimates vary significantly based on architecture choices. CRDT-based systems might reduce application server costs through simpler conflict resolution but increase storage costs through metadata overhead. The specific tradeoffs depend on your user patterns and scale.
Monitoring and Observability
Production systems require comprehensive monitoring to detect issues before they impact users. Research suggests tracking these key metrics:
Operation latency: Measure P50, P95, and P99 latencies for the complete operation cycle (client sends operation, server processes, other clients receive). Target P99 latencies under 200ms for good user experience.
Conflict rate: Track how often operations require transformation or conflict resolution. Well-designed systems typically see conflict rates below 1%, with higher rates indicating either unusual usage patterns or architectural issues.
Connection stability: Monitor WebSocket connection duration, reconnection rates, and time to reconnect. Target uptime above 99.9% for stable collaboration.
Data loss events: Implement end-to-end acknowledgment tracking to detect any operations that fail to persist. Zero data loss should be the target, with any loss events triggering immediate investigation.
Real-World Case Studies
Examining how production systems implement these concepts provides valuable perspective on tradeoffs in practice.
Google Docs
Google Docs uses a custom Operational Transformation algorithm for conflict resolution, with the server maintaining authoritative state. The system handles over 1.8 billion documents and officially supports up to 100 concurrent editors per document.
The infrastructure leverages Google's global network, which provides cross-region latencies typically under 100ms. This network advantage allows centralized operation processing while maintaining responsive user experience globally.
Google Docs' approach prioritizes consistency and auditability. The server-centric architecture enables comprehensive access control, detailed revision history, and integration with enterprise compliance requirements. The tradeoff is greater server complexity and dependency on server availability for operation processing.
Figma
Figma uses CRDTs for conflict resolution, enabling more distributed operation processing. The multiplayer server is implemented in Rust to meet low-latency requirements, and rendering uses WebGL to achieve 60fps canvas performance even with complex designs.
The CRDT approach aligns well with Figma's visual editing model. Design operations like moving objects, changing properties, or adjusting layers often have natural commutative properties. The system can tolerate network instability and even support offline editing more naturally than OT-based approaches.
Figma's architecture prioritizes performance and offline capability. The tradeoff is more complex client-side logic and larger document sizes due to CRDT metadata. For design files that already carry significant asset data, the relative metadata overhead is acceptable.
Conclusion
Building a real-time collaborative editor requires navigating a complex space of tradeoffs between consistency models, latency requirements, scaling characteristics, and operational complexity. Research provides clear guidance on some decisions: target sub-100ms latencies for responsive user experience, separate presence data from critical operations, implement comprehensive acknowledgment protocols to prevent data loss.
Other decisions depend heavily on your specific context. Choose Operational Transformation when you need centralized control and auditability. Choose CRDTs when you need distributed operation processing and offline-first capabilities. Scale connection servers horizontally to handle concurrent users, but be prepared for hotspot management when individual documents attract intense activity.
The systems we've examined handle billions of documents and millions of concurrent users, but they reached that scale through careful attention to fundamentals: low-latency networking, efficient conflict resolution, thoughtful persistence strategies, and robust handling of network instability. Whether you're building the next Google Docs or adding real-time collaboration to an existing application, these principles provide a foundation for systems that feel magical to users while remaining manageable for the engineers who operate them.
The research shows that well-designed systems achieve convergence in under one second, maintain P99 operation latencies under 200ms, and handle conflict rates below 1%. These aren't just performance targets but indicators of architectural soundness. When your system meets these benchmarks, you've likely
