Tldraw includes a multiplayer synchronization SDK (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tldraw/tldraw/llms.txt
Use this file to discover all available pages before exploring further.
@tldraw/sync) that enables real-time collaboration between users.
Basic setup with useSyncDemo
For development and testing, you can use theuseSyncDemo hook:
SyncDemoExample.tsx
How multiplayer works
Tldraw’s multiplayer system uses a client-server architecture:- Client: The tldraw editor in the browser
- Sync server: Handles real-time synchronization between clients
- Store: The shared data store that syncs across all clients
Setting up a sync server
For production, you’ll need to deploy your own sync server. The tldraw repository includes a reference implementation.1. Install dependencies
2. Create a sync worker
The sync server can be deployed as a Cloudflare Durable Object, a WebSocket server, or other real-time infrastructure. See theapps/dotcom/sync-worker directory in the tldraw repository for a complete implementation.
Custom presence
You can add custom user presence information:Room management
Creating rooms
Each collaboration session is identified by a uniqueroomId:
Multiple users
Multiple users can join the same room by using the sameroomId:
Showing collaborators
Tldraw automatically shows collaborator cursors and selections when using a sync store. You can customize the appearance:Private content
You can mark certain shapes as private so they don’t sync to other users:Conflict resolution
Tldraw uses a last-write-wins strategy for conflict resolution. Changes are timestamped and the most recent change takes precedence. For custom conflict resolution, you can:- Listen to sync events
- Detect conflicts in your application logic
- Apply custom merge strategies
Performance considerations
Optimize updates
Batch multiple changes into a single transaction using
editor.batch()Limit room size
For best performance, limit rooms to 50-100 concurrent users
Use compression
Enable WebSocket compression on your sync server
Regional servers
Deploy sync servers close to your users for lower latency
Deep links
Enable deep links to allow sharing specific views:Related
- Persistence - Save and load editor state
- Custom presence example
- Sync server reference