Why WebSockets Are NOT Scalable | WebSockets Explained

preview_player
Показать описание
In this video, I talk about why web sockets are horizontally unscalable and what can be done about it.

Timestamps
0:00 Teaser
0:18 Video Starts
0:43 Giveaway Alert!
1:02 Scalability (Vertical & Horizontal)
2:53 Websockets are not horizontally scalable
3:27 How HTTP Works?
5:03 How Websocket connection Works?
7:19 How do you make Websocket connection scalable?
11:41 Conclusion
11:53 Outro

👉 Checkout codedamn on social:

If you found the video valuable, please leave a like and subscribe ❤️ It helps the channel grow and helps me pumping out more such content.

👋 About Me:
Hey! I'm Mehul Mohan, a CSE'21 graduate from BITS Pilani, Goa. I started coding early in life, at the age of 13 when I created my first blog on Blogger. I am listed in Google, Microsoft, Sony, eSet, etc. Hall of Fame for reporting vulnerabilities in their systems.

🍎 I am Apple's WWDC'19 Scholar - visited San Francisco and attended WWDC.

🚀 Currently working on my own startup - codedamn.

Connect with me:

🏷 Video Tags:
Why WebSockets Are NOT Scalable
WebSockets Explained

Рекомендации по теме
Комментарии
Автор

We scaled our socket solution with a redis middleware that persists the session id. And it worked great. Very surprised to see no mention of this approach.

stormrider
Автор

I want to add 2 points to your video. The rise of anycast based network architectures and edge/serverless edge based architectures make us think differently about websockets and scaling them.

I've seen some interesting deployments of self hosted pbx, voip and even office tools like collabra over anycast architectures and they work quite seamlessly. There definitely will be issues/drops during scaling activity but a quick reconnection usually solves the problem.

Edge/edge serverless(like cloudflare workers) also have the same ideology as aws api gateway but the added advantage is the session is on the edge. This becomes a game changer for deployments in the above mentioned scenarios.

That said, it's not perfect. It has its problems. But the pros outweigh the cons by a big margin for about 70% of the workloads that I deal with.

brgautam
Автор

Websockets are horizontally scalable, you use a message bus where the message is sent to each websocket host also known as a backplane, and you will need to setup sticky sessions with the load balancer. The reason for this is that you don't know what server the client is on, so you send it to all of them. You can also chain websockets together e.g. a websocket server is a client of another websocket server, it's the same concept as the message bus. Also you can downscale due to redistrobution of connection via the load balancer.

jwbonnett
Автор

This video doesn't show how to scale persistent connections. Who uses websockets with AWS lambda functions? We use websockets to stream data between server and client and lambda functions are stateless and cannot remain up indefinitely.
Most applications want to maintain a connection for days, weeks or indefinitely so how does this architecture fix anything in those situations. The gateway can allow you to load balance those persistent connections but that's it.

johnboy
Автор

Websockets maintain state, so if you remove the statefulness of the connection in API gateway how would you handle a case when server wants to send a push request to clients. How does the lambda know which ws connection to try? The http connection is stateless

cschandragiri
Автор

Those AWS heads tend to forget that Nginx could balance WebSocket connections with ease.

TheHellishFrog
Автор

I was watching a WhatsApp system design video and was confused about the gateway. Luckily I found your video. Very well explained. 😊

akash-kumar
Автор

Yesterday I faced cores issue. Youtube recommended your video. Not searched in youtube.that time I am not watching tech videos, but youtube recommended. Today websocket also same happened. Currently I am building real time chat application. Thanks for your video

soorajs
Автор

Any repercussions of Amazon Lamda cold start on this scalability?

imMavenGuy
Автор

How can maintain the business logics and all sync with different servers.
I have already used the redis pub/sub but i can't sync a local objects are sync.

sarathkumarm
Автор

in the aws solution you mentioned, how would you initiate and send a message/data from server (lambdas in your case) to the client?

itskishank
Автор

Thanks for the nice video!

One question, how API gateway knows to which client the message needs to be delivered? Is there an internal queue per client automatically created by API gateway?

rdesouza
Автор

I recently implemented a tic-tak-toe game using websockets with room functionality and I didn't know websockets are hard to scale well thanks for this information, your content is great 👍

HimanshuChoudhary-smartfire
Автор

Code Damn is just an amazing channel of an amazing person...I'm really excited for this...

KrishnenduKDG
Автор

sir i am an architrct and i dont agree tht sockets arent horzntly scalable ... simply use backolane to keep connections and memory and sessions .

terasoft-official
Автор

Api Gateway is underdeveloped at the moment, missing WS features. It also have a 2 hour timeout which is very unfortunate.

yoddeb
Автор

I ran into the same problem..what I did was run a sister socket concurrently so if one socket fails..the sister socket continues to run.

marvelfancollection
Автор

Amazing, as always🔥
As a full stack dev, how should one start learning these important cloud concepts and technologies?

SleepeJobs
Автор

it's amazing can you make live experiment
video, so it will be more helpful

streamk
Автор

Hey there great clip. I think another way of doing this (not as scalable as this) would be to have an nginx as a reverse proxi in front of multiple node servers that would distribute the sokets among multiple node servers. This solution would unfortunately require you to change your code quite a bit since you wouldn't be able to guarantee that a socket is connected to the server that got a request, so the app instances would need to negotiate among themselves using a message system (maybe redis) and ask the node instance that has a connection with that particular client to send a message.

stemateflorentin
visit shbcf.ru