Syncing binary data


Thanks a lot for creating Yjs it is an amazing library. My question is:

-is could I use it to sync binary data, e.g. pictures/data files which need to be shared between all clients?

  • What is the best way to do this?
    -Write the binary data into a text field? Up to which file size would this reasonably work?
  • The binary data changes only rarely and it would be ok to sync it completely if it changes

Please excuse if this is a naive question or it has already been answered ( I searched the forum, but could not find an answer).

Thank you!

YJS is probably not the right tool to sync binary data. The benefit of YJS (which comes at significant cost in memory and bandwidth), is the conflict-free merges (i.e. the CRDT part). These are only possible with the existing shared types.

Technically you could base64 encode an image and store it in a simple Y.Array or Y.Map but I’m not sure that’s a good idea. All clients would have to store and sync every version of the image that ever existed.

I would consider storing the images in a separate location (such as on S3) and then use YJS to share hashes/urls.

1 Like

Thank you! That is helpful. I will experiment a bit with this.

Or you could just use excellent: It’s a a Yjs server with persistence and auth baked in.