Skip to main content

Overview

Excalidraw’s collaboration system enables multiple users to work on the same drawing in real-time. It handles state synchronization, conflict resolution, user presence, and file sharing through a WebSocket-based architecture with end-to-end encryption.

Architecture

The collaboration system consists of several key components:
The main orchestrator for collaboration features:
excalidraw-app/collab/Collab.tsx

Collaboration Lifecycle

1. Starting Collaboration

2. Connection Flow

3. Stopping Collaboration

State Synchronization

Element Synchronization

Elements are synchronized through a reconciliation process:
excalidraw-app/collab/Collab.tsx
When receiving remote changes, elements are reconciled using version tracking:
Reconciliation logic:
  1. Compare element versions
  2. Keep higher version number
  3. For same version, compare versionNonce
  4. Preserve local selection state
  5. Merge deleted elements appropriately

Broadcast Throttling

To optimize network usage, broadcasts are throttled:

User Presence

Pointer Tracking

packages/excalidraw/types.ts
Pointer updates are throttled to ~30fps to balance responsiveness with network efficiency.

User State Tracking

Collaborative Cursors

Remote cursors are rendered on the interactive canvas:

Following Users

Users can follow each other’s viewports:
packages/excalidraw/types.ts
When following a user:
  • Your viewport automatically scrolls to match theirs
  • Your zoom level adjusts to match theirs
  • Element selections are highlighted
  • Following can be broken by manual pan/zoom

File Sharing

Collaboration includes file synchronization for images:
File size is limited to 50MB per file. Larger files are rejected during upload.

Encryption

All collaboration data uses end-to-end encryption:
  • Uses AES-GCM encryption
  • Room key is generated as a secure random string
  • Key is never sent to the server (stays in URL fragment)
  • Each message has unique IV (initialization vector)
  • Authentication tags prevent tampering

WebSocket Protocol

The collaboration server uses Socket.IO with custom event types:
excalidraw-app/app_constants.ts
SERVER_VOLATILE
  • Pointer positions
  • Transient state updates
  • Not persisted if user disconnected
SERVER
  • Element updates
  • Selection changes
  • File uploads
  • Persisted and replayed on reconnection

Collaborative Features

Remote Selection Highlights

Collaborative Locking

packages/excalidraw/types.ts

Scene Versioning

getSceneVersion is deprecated. Use hashElementsVersion for better collision resistance in large scenes.

Error Handling

excalidraw-app/collab/CollabError.tsx

Connection States

Integration Example

Best Practices

  • Throttle broadcasts to prevent network flooding
  • Use volatile events for transient state (cursors)
  • Batch element updates when possible
  • Compress large payloads before encryption
  • Implement exponential backoff for reconnection
  • Trust version numbers for element reconciliation
  • Never decrement version numbers
  • Use versionNonce for same-version conflicts
  • Preserve user intent during reconciliation
  • Handle deleted elements gracefully
  • Never send encryption keys to server
  • Validate all incoming data before decryption
  • Sanitize user-provided content (usernames, etc.)
  • Implement rate limiting for broadcasts
  • Handle malformed messages gracefully
  • Show clear collaboration status indicators
  • Display collaborator avatars and names
  • Provide feedback for connection issues
  • Allow easy copying of room links
  • Implement graceful degradation when offline

Performance Considerations

For scenes with many elements:
  • Use incremental updates instead of full syncs
  • Implement spatial indexing for collision detection
  • Throttle reconciliation frequency
  • Consider delta compression
  • Elements - Element versioning and reconciliation
  • Scene - Scene state management
  • App State - Collaboration-related state properties