TLDR;
Slack sends tons of messages everyday on their workplace communication app.
→ The flow a message takes its message
→ It goes to an admin server to look up which server the channel is on
→ Channel server works on broadcasting to all clients on the server.
📺 It’s not TV but there’s channels
Slack has a ton of channels. They’re all grouped together on specific servers. The name for these servers is unsurprisingly called “channel servers”
Every slack channel has a channel id, pretty much a channel number. These channels are stored on specific servers based on their hash
The Super Simple Example:
Channels 1-100 are on channel server 1
Channels 101-200 are on channel server 2…
and so on.
🔌 What if we change the channel?
How does slack know which requests belong to which channel?
We won’t go in too much detail but it’s based off of consistent hashing on the slack ids.
⚡ Set me up with the setup
Here’s how Slack’s architecture works when anyone logs into the app. Diagram looks scary. Lets talk about to make it not scary.
Get some user data from the webapp server.
Make a web socket connection to listen to get messages pushed from the server
Send that request to this gateway server. Gateway server is just a fancy word for knowing where the slack channels are based on Id.
These are region based. Meaning there’s gateway servers for being in the United States and being in India or any other country.
Get the channel data on the user’s webapp server somewhere else.
Send the response back to the proxy server.
Forward that response back to the client.
Keep the channel directory gateway server subscribed to the related channel servers.
🗓️ That’s Uneventful. But Knowing When Someone is typing is.
So what about that little feature that says “Your boss is typing…”. I get anxiety over this one too.
How Events Work
Knowing when someone is typing is an “event” for slack. They process the event mostly the same way how they process messages.
Send an event to envoy (the service proxy)
Send that event to a gateway server to figure out which channel ids it belongs to
Let the gateway server send it to the actual channel server.
Wait for that channel server to broadcast it to other gateway servers in other regions
Other people get the event and you see “your boss is typing…”
🖥️ Wait. I Don’t See The Difference Between Events and Messages.
The only difference is there’s an admin server for messages. The only thing an admin server does is interact with the backend like storing things in databases or scheduling messages.
💰 HELP WANTED
This newsletter has grown to 5000+ AMAZING READERS. It’s grown to a scale that a single person can’t maintain all of it on their own.
If you’re interested in being a byte-sized design writer, reach out directly to hello@alexcancode.io
📝 Official Article
(Links to official article and sources are available to paid subscribers. They help maintain and support this newsletter!)
Keep reading with a 7-day free trial
Subscribe to Byte-Sized Design to keep reading this post and get 7 days of free access to the full post archives.