yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
499 stars 258 forks source link

Question: why server need a centralized doc ? #16

Closed zlv-thisF closed 4 years ago

zlv-thisF commented 4 years ago

hey all, i am a bit confused about the collab-demo:https://github.com/yjs/y-prosemirror with y-websocket here.

in the demo, server holds a centralized doc, ws listen to client update and applyUpdate on 'server-ydoc', then broadcast server update to each 'client-ydoc' which will turn into prosemirror's transaction. I am new to yjs, in my opinion, CRDT is not basd on centralized node, why not server broadcast all client updates to each client directly since document updates are commutative and idempotent?

image

image

the README.MD 's two suggestion is also based on sync client update to server then broadcast update which occurred in the server side, why should we do like that? image

thanks.

dmonad commented 4 years ago

Hi @zlv-thisF ,

Yjs is network agnostic. That means it works with any communication protocol. You just need some way of propagating all changes to all clients.

Yjs has many network providers to allow shared editing using webrtc, websocket, dat, and for v12 there also exist modules for IPFS and XMPP. This is explained in the README. Let me know if that was unclear.

For many applications, it is still advantageous to have servers. Servers tend to be more reliable than p2p WebRTC connections. Furthermore, many applications want to index the data on a server anyway. The big advantage of Yjs is that you can scale the servers in a distributed manner. Option 1 describes a decentralized approach, that just uses PubSub to share document updates. The main advantage of Yjs over centralized approaches like ShareDB is that the whole system doesn't break if one server fails. You can simply start another server doing conflict resolution.

I'm gonna close this issue for now, but let me know if you need more clarification.

zlv-thisF commented 4 years ago

thanks for you patient, now i get it ! thanks a lot !