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?
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.
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
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.
Discord doesn't simply use the mentioned technologies alone
Some of the important tricks they currently use are: