In the system design diagram there are:
- 3 chats,
- every chat has 4 users.
- GW -> socket gateway server that handles client's socket.
- Chat API is separate for simplicity to not cover processing of the messages on the GW itself
You can see that if we have much larger participants count than number of GW nodes we end up every GW node handle ALL large chats, thus causing broadcast.
===
This is one of the canonical solution that I saw on the internet for Messenger: you connect user to random GW and this GW gets (somehow) the message to deliver to the users that are connected to it. The solution is actually the way it works in Telegram and other Messengers, you have only single socket connection, it does not change when you switch chat.
First screen: 2 GW, 4 users per large chat => 4 / 2 = 2 users on EACH GW for EACH large chat
Second screen: we scaled GW nodes by 2 = 4 GW nodes -> and it didn't fix the broadcast, thus non linearly scalable
- 3 chats,
- every chat has 4 users.
- GW -> socket gateway server that handles client's socket.
- Chat API is separate for simplicity to not cover processing of the messages on the GW itself
You can see that if we have much larger participants count than number of GW nodes we end up every GW node handle ALL large chats, thus causing broadcast.
===
This is one of the canonical solution that I saw on the internet for Messenger: you connect user to random GW and this GW gets (somehow) the message to deliver to the users that are connected to it. The solution is actually the way it works in Telegram and other Messengers, you have only single socket connection, it does not change when you switch chat.
First screen: 2 GW, 4 users per large chat => 4 / 2 = 2 users on EACH GW for EACH large chat
Second screen: we scaled GW nodes by 2 = 4 GW nodes -> and it didn't fix the broadcast, thus non linearly scalable
π₯5
andreyka26_se
In the system design diagram there are: - 3 chats, - every chat has 4 users. - GW -> socket gateway server that handles client's socket. - Chat API is separate for simplicity to not cover processing of the messages on the GW itself You can see that ifβ¦
chat.excalidraw
165.4 KB
Please let me know about your ideas, as today-tomorrow I plan to finish the article, so that you can test your idea as well, as I gonna write bunch of simulations, calculations, POC etc.
In case someone would want to play with diagrams, attaching excalidraw for the diagrams
In case someone would want to play with diagrams, attaching excalidraw for the diagrams
π₯3
Daily (239/373 streak until LC cap)
Easy and 'free' problem basically, you need 30 seconds for it
https://leetcode.com/problems/robot-return-to-origin/description/?envType=daily-question&envId=2026-04-05
#daily #easy #nopattern
Easy and 'free' problem basically, you need 30 seconds for it
https://leetcode.com/problems/robot-return-to-origin/description/?envType=daily-question&envId=2026-04-05
#daily #easy #nopattern
π3
andreyka26_se
In the system design diagram there are: - 3 chats, - every chat has 4 users. - GW -> socket gateway server that handles client's socket. - Chat API is separate for simplicity to not cover processing of the messages on the GW itself You can see that ifβ¦
Other way to show it. In this diagram (screen 1), we have only 1 chat with 4 participants per chat and 1 message per second coming to this chat from one of the clients (out of scope).
Do you see it? Every WS Gateway have to process all messages, as chat participants are connecting randomly (or deterministically but based on user_id property).
From now on, unless number of WS Gateways is more than max number of participants in chat - it will always be the case. Check screen 2, number of nodes = 5 > participants per chat = 3 (top 3 clients => chat1, bottom 3 clients => chat2). Now WS gateways process 1 message per second, except WS Gateway1, because he has users from both chats.
Screen 3 - is the same scaled situation but with single chat
Do you see it? Every WS Gateway have to process all messages, as chat participants are connecting randomly (or deterministically but based on user_id property).
From now on, unless number of WS Gateways is more than max number of participants in chat - it will always be the case. Check screen 2, number of nodes = 5 > participants per chat = 3 (top 3 clients => chat1, bottom 3 clients => chat2). Now WS gateways process 1 message per second, except WS Gateway1, because he has users from both chats.
Screen 3 - is the same scaled situation but with single chat
π₯6
Daily (240/373 streak until LC cap)
Today is good problem, not bullshit, I like when it has some sort of simulation and objects to play with.
https://leetcode.com/problems/walking-robot-simulation/description/?envType=daily-question&envId=2026-04-06
#daily #medium
Today is good problem, not bullshit, I like when it has some sort of simulation and objects to play with.
https://leetcode.com/problems/walking-robot-simulation/description/?envType=daily-question&envId=2026-04-06
#daily #medium
β€5
andreyka26_se
So, it is the time. Do you want to try yourself for System Design? You remember I said I don't know the good real prod solution for Messenger System Design? It is time to shine and give your ideas, while I'm prepping the article, so that I can consider allβ¦
So,
Guys, I am finishing the article.
Anything except:
1. Chat api pushing message updates directly to GW nodes (socket stateful nodes)
2. Chat api publishes message update to queue per user
3. Chat api publishes message update to queue per chat
These are typical what I have seen on the forums.
Shout if you have some different approach in your mind. It is okay that it might be not correct. Also can be the real solution and I will defeat with my arguments
Guys, I am finishing the article.
Anything except:
1. Chat api pushing message updates directly to GW nodes (socket stateful nodes)
2. Chat api publishes message update to queue per user
3. Chat api publishes message update to queue per chat
These are typical what I have seen on the forums.
Shout if you have some different approach in your mind. It is okay that it might be not correct. Also can be the real solution and I will defeat with my arguments
π₯6
Daily (241/373 streak until LC cap)
Interesting problem, a bit bullshit as there is no pattern to learn, but fun, with funny corner case xD
https://leetcode.com/problems/walking-robot-simulation-ii/description/?envType=daily-question&envId=2026-04-07
#daily #medium #nopattern
Interesting problem, a bit bullshit as there is no pattern to learn, but fun, with funny corner case xD
https://leetcode.com/problems/walking-robot-simulation-ii/description/?envType=daily-question&envId=2026-04-07
#daily #medium #nopattern
π4
Daily (242/373 streak until LC cap)
Should be easy instead of mid, 2 mins to solve, just simulate what is written. The only thing that worries me the number "I" in the title. Probably tomorrow we gonna have fucking hell problem.
https://leetcode.com/problems/xor-after-range-multiplication-queries-i/description/?envType=daily-question&envId=2026-04-08
#daily #medium #nopattern
Should be easy instead of mid, 2 mins to solve, just simulate what is written. The only thing that worries me the number "I" in the title. Probably tomorrow we gonna have fucking hell problem.
https://leetcode.com/problems/xor-after-range-multiplication-queries-i/description/?envType=daily-question&envId=2026-04-08
#daily #medium #nopattern
π₯3π2
andreyka26_se
Daily (242/373 streak until LC cap) Should be easy instead of mid, 2 mins to solve, just simulate what is written. The only thing that worries me the number "I" in the title. Probably tomorrow we gonna have fucking hell problem. https://leetcode.com/problems/xorβ¦
Daily (243/373 streak until LC cap)
Told you guys :) Don't do this nonsense, it is legit nonsense. I would rather spend time tomorrow and eventually finish fucking article.
https://leetcode.com/problems/xor-after-range-multiplication-queries-ii/description/?envType=daily-question&envId=2026-04-09
#daily #hard #nopattern
Told you guys :) Don't do this nonsense, it is legit nonsense. I would rather spend time tomorrow and eventually finish fucking article.
https://leetcode.com/problems/xor-after-range-multiplication-queries-ii/description/?envType=daily-question&envId=2026-04-09
#daily #hard #nopattern
π3
Daily (244/373 streak until LC cap)
Easy one, actually good for some simple leetcode patterns. Recommended
https://leetcode.com/problems/minimum-distance-between-three-equal-elements-i/description/?envType=daily-question&envId=2026-04-10
#daily #easy #pattern
Easy one, actually good for some simple leetcode patterns. Recommended
https://leetcode.com/problems/minimum-distance-between-three-equal-elements-i/description/?envType=daily-question&envId=2026-04-10
#daily #easy #pattern
π3
This media is not supported in your browser
VIEW IN TELEGRAM
Back in the game. Also want to try again some group trainings for a couple of times to remind myself some youth moments
π₯15
Daily (245/373 streak until LC cap)
The same problem as yesterday with stricter constraints. (Yesterday's optimized solution will work)
https://leetcode.com/problems/minimum-distance-between-three-equal-elements-ii/description/?envType=daily-question&envId=2026-04-11
#daily #medium #pattern
The same problem as yesterday with stricter constraints. (Yesterday's optimized solution will work)
https://leetcode.com/problems/minimum-distance-between-three-equal-elements-ii/description/?envType=daily-question&envId=2026-04-11
#daily #medium #pattern
π5
https://andreyka26.com/messenger-system-design-is-wrong
Eventually, after 1 month, I did it π
Please share your thoughts. It is just article that explains the problem but does not have a solution
#systemdesign
Eventually, after 1 month, I did it π
Please share your thoughts. It is just article that explains the problem but does not have a solution
#systemdesign
andreyka26 tech
Messenger System Design is WRONG
Why do all popular Messenger System Design solutions - Direct GW, Pub/Sub by user, Pub/Sub by chat - fail to linearly scale for large chats with 10k+ participants? This article breaks down the fundamental bottleneck in WebSocket Gateway scaling and proposesβ¦
1π₯19β€2