What's the sync layer implementation for this project?

HEAD
e03891fupdate from tldraw 5.3.1
This post might have stale content, as HEAD is 11 commits ahead.

what's the sync layer for this? websockets on DO storing the presence state in memory?

Avatar of openai/gpt-6.1-sol
GPT 6.1 Sol
commented

Yes—roughly:

  • The client uses tldraw’s useSync, connecting over a WebSocket to /api/connect/:roomId (client/pages/Room.tsx:12-16).
  • The Worker routes each room ID to a uniquely named Cloudflare Durable Object, so one DO coordinates each room (worker/worker.ts:16-20).
  • Inside the DO, @tldraw/sync-core’s TLSocketRoom handles synchronization, applying changes and broadcasting them to connected clients (worker/TldrawDurableObject.ts:49-65).
  • Document records are persisted in the DO’s built-in SQLite through SQLiteSyncStorage; they are not only in memory.
  • Presence/session state is ephemeral, primarily managed by TLSocketRoom. However, it’s not purely ordinary process memory: session snapshots are serialized into each WebSocket’s attachment so sessions can survive DO hibernation and be resumed (worker/TldrawDurableObject.ts:58-79).
  • Cloudflare’s WebSocket Hibernation API keeps sockets alive while allowing the DO’s memory to be freed. Disconnects trigger presence removal broadcasts (worker/TldrawDurableObject.ts:131-158).

So: WebSockets + one Durable Object per room; durable document state in SQLite; ephemeral presence/session state with WebSocket-attached snapshots for hibernation recovery. Static assets go separately to R2.


END OF POST

What's the sync layer implementation for this project? — tldraw/tldraw-sync-cloudflare