跳至主要内容

[Google Docs] Architecture - Network

Network

For collaborative editing, we need to support real-time communication between users.

There are 2 main ways to support real-time communication:

  1. Client-Server Model (WebSocket)
  2. Peer-to-Peer (WebRTC)


Client-Server Model (WebSocket)

WebSocket

The client server model is that we use a central server (or multiple servers) to handle all connections and collaborative behaviors.


Pros and Cons

FeaturesRatingDescription
Centralized source of truth🟢All users have the same document from single source
Scalability🟢Event hard to load balancing for Servers, comparing to peer-to-peer, only Server need to handle all connections
Implementation🟢Comparing to peer-to-peer, the concept is simpler
Single point of failure🔴Once server is down, all users cannot collaborate
Cost🔴We need a long live server to handle all connections, which is hard to maintain
Speed🔴Comparing to peer-to-peer, we need to go through server, which increase a network path



Peer-to-Peer (WebRTC)

Peer to Peer

The peer-to-peer model is that only rely on clients themselves to handle all connections and collaborative behaviors.


Pros and Cons

FeaturesRatingDescription
Single point of failure🟢Even if any client is down, the other clients can still collaborate
Cost🟢We don't need a long live server to handle all connections, only rely on clients themselves
Speed🟢We can directly communicate with each client
Centralized source of truth🔴There is no centralized source of truth, each client is the authority
Scalability🔴When clients increase, every client have to handle more connections, which become a complex mesh
Implementation🔴The concept and implementation of peer-to-peer is way more complex than client-server model


Conclusion : Which one to use?

Here are the pros and cons of each model:

Features🏆 Client-Server ModelPeer-to-Peer Model
Single point of failure🔴🟢
Cost🔴🟢
Speed🔴🟢
Centralized source of truth ⭐️⭐️⭐️🟢🔴
Scalability🟢🔴
Implementation🟢🔴


Since what document value is document's correctness, which can be achieved by centralized source of truth on server. And Client-Server Model is easier to scale, 🏆 Client-Server Model will be our choice.



Reference