Did you know how discord/zoom works?


2 min read

The secret ingredient is WebRTC.

Here I think that the communication protocols I need to pick when developing a new solution are GRPC, REST, Websockets, and GraphQL.

Thanks for reading Amr’s Newsletter! Subscribe for free to receive new posts and support my work.

Since we are talking about real-time communication by default we will drop others beside WebSockets.

that’s when I saw WebRTC when reading this discord article.

What is WebRTC?

WebRTC is a fully peer-to-peer technology for the real-time exchange of audio, video, and data, with one central caveat. A form of discovery and media format negotiation must take place.

in order for two devices on different networks to locate one another. This process is called signaling and involves both devices connecting to a third, mutually agreed-upon server. Through this third server, the two devices can locate one another, and exchange negotiation messages.

So here is my short reflection:

Good side

  • Fast as long as your use case doesn’t require all packets delivery in order

Uses UDP which explains why it’s faster than WebSocket which uses TCP.

peer-to-peer technology and once the connection is up and running, you do not need to pass the communication via a server (unless using TURN).

  • Secure

With WebSockets, the data has to go via a central webserver which typically sees all the traffic and can access it.

With WebRTC the data is end-to-end encrypted and does not pass through a server (except sometimes TURN servers are needed, but they have no access to the body of the messages they forward).

I was curious to see its compatibility with all browsers and it seems solid Screenshot from 2022-10-03 20-43-01.png


Bad side

Require a singling server

complex API compared to WebSockets, but there are many packages that work toward solving that.

When should you use WebRTC instead of a WebSocket?

Almost never. That’s the truth.

If you’re contemplating between the two and you don’t know a lot about WebRTC, then you’re probably in need of WebSockets, or will be better off using WebSockets.

I’d think of data channels either when there are things you want to pass directly across browsers without any server intervention in the message itself (and these use cases are quite scarce), or you are in need of a low latency messaging solution across browsers where a relay via a WebSocket will be too time consuming.

Resources time: