This content originally appeared on DEV Community and was authored by Abdulrahman S.
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:
- MessagePack for payload compression
- Redis for cache and pubsub clients
- Snowflake for generating IDs
Open-source projects that follow discord philosophy:
This content originally appeared on DEV Community and was authored by Abdulrahman S.
Abdulrahman S. | Sciencx (2022-07-15T19:56:29+00:00) How discord manage 300M socket connection. Retrieved from https://www.scien.cx/2022/07/15/how-discord-manage-300m-socket-connection/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.