Discord - Architecture
Managing user sessions and guilds
Discord uses Elixer processes per user session (user can have multiple sessions, from mobile, pc, etc) and 1 process per guild.
Any events in the guild, is then fanout notifications to all the users in the system.
Improved architecture adds Relays
where the guild can split the work of fanning out notification to intermediate servers.
Updates were only sent to active users and not the passive users. Passive users are the ones who are not online and not actively viewing the guild (might be viewing another guild, offline, etc).
Data storage: Read and writes to DB (ScyllaDB)
Discord Data Service
optimises read requests by providing Request Coalescing
. If multiple users are requesting for the same row at the same time, the DB is queried only once. Subsequent requests will check for the existence of that task and subscribe to it. That worker task will query the database and return the row to all subscribers.
Multiple Data service
servers are available at a time and with consistent hashing (in this case, each request has a channel ID as the routing id), all data requests to a channel will be routed to the same Data Service
to leverage request coalescing.