So, how they solved it? ๐ง๐ต๐ฒ๐ ๐ณ๐ถ๐ฟ๐๐ ๐๐ฟ๐ถ๐ฒ๐ฑ ๐๐ผ ๐๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ ๐ต๐ผ๐ ๐๐ต๐ฒ ๐๐๐๐๐ฒ๐บ ๐ฝ๐ฒ๐ฟ๐ณ๐ผ๐ฟ๐บ๐. They tracked what Elixir processes were doing, if they were stuck waiting on something, etc. They recorded the event types, how many of each kind of message they received, and their processing times. In addition, they tried to understand how much memory they use, the performances of garbage collectors, etc.
After the analysis, they ๐ฐ๐ฟ๐ฒ๐ฎ๐๐ฒ๐ฑ ๐๐ต๐ฒ ๐ณ๐ผ๐น๐น๐ผ๐๐ถ๐ป๐ด ๐๐๐ฟ๐ฎ๐๐ฒ๐ด๐:
๐ญ. ๐ฃ๐ฎ๐๐๐ถ๐๐ฒ ๐๐ฒ๐๐๐ถ๐ผ๐ป๐: Discord significantly reduced the amount of data processed and sent by differentiating between active and passive user connections, cutting the fanout work by 90% for large servers.
๐ฎ. ๐ฅ๐ฒ๐น๐ฎ๐๐: Implementing a relay system (read - multithreading) allowed Discord to split the fanout process across multiple machines, enabling a single guild to utilize more resources and support more prominent communities. Relays maintain connections to the sessions instead of the guild and are responsible for doing fanout with permission checks.
๐ฏ. ๐ช๐ผ๐ฟ๐ธ๐ฒ๐ฟ ๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐๐ฒ๐ ๐ฎ๐ป๐ฑ ๐๐ง๐ฆ: To maintain server responsiveness, Discord employed worker processes and Erlang Term Storage (ETS) for operations requiring iteration over large sets of members, thus avoiding bottlenecks in the guild process. ETS is an in-memory database that supports the ability of multiple Elixir processes to access it safely. This enables the creation of a new worker process and passes the ETS table so this process can run expensive operations and offload the central guild server.
๐
https://discord.com/blog/maxjourney-pushing-discords-limits-with-a-million-plus-online-users-in-a-single-server