DEV Community

Abdulrahman S.
Abdulrahman S.

Posted on

How discord manage 300M socket connection

discord-banner

Overview

Discord, the popular platform famous for its complex system of guilds and detailed permissions. how they managed to handle this amount of websocket connections with permissions in mind?

Publish–subscribe Pattern (also known as Pub/sub)

The Pubsub pattern is a one-to-many relationship that allows to publish specific event/data to multiple subscribers/users at the same time.
This pattern has already been implemented in many technologies such as redis and postgres and much others.

Permissions

The magic behind discord it's the permission system
Most of us may think of permissions as a list of strings.
But actually they are numbers exactly 64 unsigned integers
They use a data structure called bitfields
It's powerful in terms of performance

How Discord uses these technologies?

When you connect to their websocket server, they create a pubsub client and this client subscribes to your friends, servers, groups and other important IDs to send you back updates
But before sending you back anything they check your permissions with the target of X.

The tricks to handle the load

Discord doesn't simply use the mentioned technologies alone
Some of the important tricks they currently use are:

Open-source projects that follow discord philosophy:

Top comments (0)