How Discord handles Millions of users talking at real time
Let’s take some inspiration from Discord and how they build their robust infrastructure that handles millions of requests.
This will help us to design the underlying architecture for our SaaS startup.
Discord has a user base of around 40 billion, and 100 million messages are sent on Discord every day.
Programs like Midjourney use Discord as their interactive user interface, they don’t have any app or dedicated SaaS but rather ask you to join their community where you can create images.
What we know is Discord uses these tech stacks for their backend, the algorithm that is responsible for taking the message coming from one server and distributing it to multiple.
GUID (Elixir)
Python/Go APIs to handle the Client and Backend
Some optimizations were made so users don’t receive unnecessary notifications.
The server to which you are not active but you joined Discord will not send you a notification for it, they mark such users as Passive Users.
For such users they only load the information of the chat when they click or go inside the server.
Something very useful as they don’t need to send messages to you everytime, we should also make sure to implement such checks on our SaaS too.
Discord also introduced something called Relays in their architecture as till now there was only 1 service GUID (Elixir) responsible for getting the message from one side and then distributing it to the other users.
It was similar to the concept of Workers and Slaves, where there is one master node whose job is to distribute the load among multiple slave or worker nodes.
There was also a big issue with one feature, when someone sends an everyone message the discord algorithm has to pick everyone on that server. They solved this by introducing an ETS system.
Think of the ETS system as offloading a bunch of work from servers to smaller devices.
Also, at some point, Discord changed its database from MogngoDB to Cassandra.
This was pretty much it, I hope we all can take some learning and inspiration from Discord and the work their engineers have done.
I have also written a book on marketing if you want to take a deep dive into marketing and know how to get long-term paying customers for your SaaS, “Marketing Strategies to Grow Your SaaS” which will cover all the necessary steps and strategies in depth to help you take your SaaS from scratch and get some real paying users.