Persisting to DB, could it be this easy?

Hi @mikkokam

Sure that would work, and it is actually how applications like room.sh work with Yjs. They use y-webrtc and then store the document on some server (if there is any).

The downside of this approach is that you can’t always determine if a document is …

  1. synced to the server. What happens if the user is closing the document before your app can sync it to a server?
  2. completely synced to the server. In case two users are concurrently syncing a change, you can’t determine if all latest changes are synced. For example, there might be a proxy that prevents a client to sync via webrtc, then the client behind the proxy will overwrite all document updates from other users with an old state.

Generally, I recommend to add more reliability to an application. There are tremendous benefits in having a server that accepts granular updates:

  • You don’t need to sync-up the complete document state (few hundred kbs) in an interval
  • Document updates that are synced to the server won’t be lost when you close your application window
  • Allows faster syncing with the clients. No need to sync the complete document state, only the differences are exchanged.

I’m also currently working on enabling applications to sync changes without loading them to memory. I described my approach here: https://github.com/yjs/yjs/issues/263 Once this is done, I will rewrite the server to work on the binary format directly.

2 Likes