No video

Why WebSockets Are NOT Scalable | WebSockets Explained

  Рет қаралды 33,259

Mehul - Codedamn

Mehul - Codedamn

Күн бұрын

In this video, I talk about why web sockets are horizontally unscalable and what can be done about it.
⚛️ Learn Full Stack Development on codedamn: cdm.sh/fullstack
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
👉 Free HTML5 + CSS3 Course: cdm.sh/htmlcss...
👉 Free JavaScript Course: cdm.sh/jsbasic...
👉 Free ReactJS Course: cdm.sh/react
👉 Free NextS Course: cdm.sh/nextjsb...
💰 Refer codedamn to friends and earn $$: cdm.sh/refer
👉 Checkout codedamn on social:
Instagram: cdm.sh/ig
Twitter: cdm.sh/twt
Facebook: cdm.sh/fb
GitHub: cdm.sh/github
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.
📙 I am an author of 2 books, on JavaScript and React - cdm.sh/mehulbooks
🚀 Currently working on my own startup - codedamn.
Connect with me:
📸 Instagram: cdm.sh/mehulig
📱 Twitter: cdm.sh/mehultw...
📝 LinkedIn: cdm.sh/mehulli...
📂 GitHub: cdm.sh/mehulgi...
🌎 Personal website: cdm.sh/mehulblog
💻 Start learning to code for free: cdm.sh/codedamn
🧑‍🤝‍🧑 Discord community: cdm.sh/discord
👉 HTML5 + CSS3 Tutorials: cdm.sh/htmlcss...
👉 Complete JavaScript Tutorial: cdm.sh/jstutorial
👉 Complete React Crash Course: cdm.sh/reacttu...
👉 Next JS Tutorials: cdm.sh/nextjsy...
🏷 Video Tags:
Why WebSockets Are NOT Scalable
WebSockets Explained
👉 Check out my other personal KZbin channel (it is in Hindi/English mix) where I share coding tips, tricks, and hacks: cdm.sh/mehulyt

Пікірлер: 99
@codedamn
@codedamn 2 жыл бұрын
Learn WebSockets and other Full Stack Technologies on codedamn: cdm.sh/fullstack
@Animelover-ds9vg
@Animelover-ds9vg 2 жыл бұрын
Hey Mehul, can you please show us how to implement this by a project maybe a simple chat app or something.. mostly we all use sockets for chat app ig
@stormrider22
@stormrider22 Жыл бұрын
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.
@jwbonnett
@jwbonnett Жыл бұрын
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.
@fawazsullia5620
@fawazsullia5620 10 ай бұрын
This is the right answer. The solution in this video isn't a good one
@the_maroon_knight
@the_maroon_knight 10 ай бұрын
I am really confused by this one. Is there any resource from which I can actually read this up?
@iamcrabgod2809
@iamcrabgod2809 7 ай бұрын
Yes, I was also thinking same way. Why can't we use Kafka here...and assign a key to each client so that we will know to which server it can map to...that way we don't have to send it to every server
@adR9990
@adR9990 6 ай бұрын
@jwbonnett suggestion is the correct approach, leverage message brokers and pub/sub for horizontally scaled instances of a server to publish messages for changes it makes which get broadcast by the message broker to the instances subscribing to that event. Those instances will then send those updates its client connections. This is how all clients know about changes by other clients in real-time. Load balancer tracks the client sessions using sticky sessions feature which uses least connection algorithm to load balance the connections to the replicated server instances. This video covers the topic well: kzbin.info/www/bejne/rImtpH1rZ9uqd6M
@brgautam
@brgautam 2 жыл бұрын
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.
@codedamn
@codedamn 2 жыл бұрын
I don’t know a lot about anycast networks but this sounds very interesting. Thank you for sharing. Do you have any reading materials on this?
@brgautam
@brgautam 2 жыл бұрын
@@codedamn at a high level, anycast is a faster backbone to your origin server. In aws you can do it with global accelerator. You can setup global accelerator + ec2 or nlb as origin with multiregion deployment. In Google cloud, you can use Google load balancer and that also does the same thing. Throw in a random websocket server and play around with multi region with peak load. There is a noticeable amount of difference. Btw, you have some great content in your channel. Hats off for your effort.
@johnboy14
@johnboy14 Жыл бұрын
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.
@cschandragiri
@cschandragiri Жыл бұрын
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
@HimanshuChoudhary-smartfire
@HimanshuChoudhary-smartfire 2 жыл бұрын
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 👍
@reprovedcandy
@reprovedcandy Жыл бұрын
I have a friend who has a socket based business that grew 100x faster than they expected. His life was hell scaling that software lol I also had a socket based business that I just recently sold. Only had a few thousand users but i never had a single issue with the sockets.
@phantombeing3015
@phantombeing3015 Жыл бұрын
​@@reprovedcandy then, what is alternative?
@stemateflorentin1715
@stemateflorentin1715 2 жыл бұрын
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.
@stormrider22
@stormrider22 Жыл бұрын
Redis, bingo.
@terasoft-official
@terasoft-official Жыл бұрын
sir i am an architrct and i dont agree tht sockets arent horzntly scalable ... simply use backolane to keep connections and memory and sessions .
@TheHellishFrog
@TheHellishFrog 5 ай бұрын
Those AWS heads tend to forget that Nginx could balance WebSocket connections with ease.
@KishanKumar-ht4vo
@KishanKumar-ht4vo 2 ай бұрын
in the aws solution you mentioned, how would you initiate and send a message/data from server (lambdas in your case) to the client?
@rdesouza82
@rdesouza82 2 жыл бұрын
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?
@crimsoncad3230
@crimsoncad3230 2 жыл бұрын
Just a helpful info. AWS Api Gateway needs to respond within 30 sec. If the backend behind the gateway takes more than 30sec then the API Gateway will directly respond with TIMEOUT json.
@akash-kumar737
@akash-kumar737 2 жыл бұрын
I was watching a WhatsApp system design video and was confused about the gateway. Luckily I found your video. Very well explained. 😊
@SleepeJobs
@SleepeJobs 2 жыл бұрын
Amazing, as always🔥 As a full stack dev, how should one start learning these important cloud concepts and technologies?
@soorajs577
@soorajs577 2 жыл бұрын
Yesterday I faced cores issue. KZbin 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
@marvelfancollection3690
@marvelfancollection3690 2 ай бұрын
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.
@KevinBoutin
@KevinBoutin Жыл бұрын
Serverless will absolutely allow horizontally scaling of web sockets. Each message is dispatched to a serverless function for processing.
@KrishnenduKDG
@KrishnenduKDG 2 жыл бұрын
Code Damn is just an amazing channel of an amazing person...I'm really excited for this...
@djangbahevans1
@djangbahevans1 8 ай бұрын
Websockets are hard to scale but not impossible to scale. Using a service as recommended here doesn't really solve it, but rather just passes the problem on to AWS. That might or might not be acceptable depending on your business needs.
@avirads
@avirads 2 ай бұрын
great explanation. thanks.
@keshavmishra2397
@keshavmishra2397 2 жыл бұрын
Your content is always amazing!
@JavierMonsuarez
@JavierMonsuarez 2 жыл бұрын
Your are giving a misleading information (not in purpose, I know) but WS are as scalable as TCP connections are. You should say that node.js is not scalable, instead.
@programmer1356
@programmer1356 2 жыл бұрын
Also, I think what he should say is that websockets are not downscalable which seems to be the only problem he mentions.
@ChrisAthanas
@ChrisAthanas Жыл бұрын
Yes the downscale issue seems to be the main concern
@ajsyt
@ajsyt 2 жыл бұрын
2:21 Until the world runs out of silicon 😂
@yoddeb
@yoddeb Жыл бұрын
Api Gateway is underdeveloped at the moment, missing WS features. It also have a 2 hour timeout which is very unfortunate.
@smaranh
@smaranh 2 жыл бұрын
Another alternative is switching to gRPC which can provide bidirectional communication.
@Sonu-tg6tg
@Sonu-tg6tg 2 жыл бұрын
Thank you so much for this, your videos are really awesome with great video quality and content too. With help of your videos now I am able to build web projects. Thanks a lot!!
@SushilKumar-ig8ls
@SushilKumar-ig8ls 2 жыл бұрын
Thank you for giving solutions to problems. It was really a good concept to understand and know.
@vinayakbhat8495
@vinayakbhat8495 11 ай бұрын
Good explanation. Thanks!
@arvindshelke8889
@arvindshelke8889 2 жыл бұрын
Thanks, i was trying to learn sockets, it helps!
@staplepin8099
@staplepin8099 2 жыл бұрын
ERLANG VM entered the chat 🤣
@braintricker_soft
@braintricker_soft 5 ай бұрын
Use message broker to publish message centrally to every instance of web socket server
@santhoshk9285
@santhoshk9285 2 жыл бұрын
codedamn forever 🔥
@codedamn
@codedamn 2 жыл бұрын
Hey! Congrats on Winning the codedamn T Shirt Giveaway. Please reply to this comment by mentioning your email for further communication. Or just go on your channel page and set an email address so that we can contact you that way. Or just reply here without using @ gmail . com.
@akshaygadekar9926
@akshaygadekar9926 2 жыл бұрын
I always used to think if websockets are that of much fast, why use http, but now understood they are not reliable and scalable so http is better, thanks codedamn. Can you please tell us which language is better to us websockets on, php node or python....
@md.hasanmahmudrimon9867
@md.hasanmahmudrimon9867 2 жыл бұрын
Your information is much appreciated
@sghayeroumayma8506
@sghayeroumayma8506 2 жыл бұрын
This is great! thank you.
@hemantkawale6945
@hemantkawale6945 11 ай бұрын
Great video.
@marvelfancollection3690
@marvelfancollection3690 Ай бұрын
Bro you can vertical..the the idea is spread the load over the ports
@AvigyanBhakta
@AvigyanBhakta 2 жыл бұрын
Real good explanation 👍
@melwin217
@melwin217 2 жыл бұрын
Is this related to system design?
@stream8k
@stream8k Жыл бұрын
it's amazing can you make live experiment video, so it will be more helpful
@shrestha0144
@shrestha0144 2 жыл бұрын
Every time i get notified of your video, i come here as soon as I can
@alex_ventura
@alex_ventura 2 жыл бұрын
Great video!
@aj35lightning
@aj35lightning 2 жыл бұрын
doesn't phoenix channels use very horizontally scaleable websockets?
@staplepin8099
@staplepin8099 2 жыл бұрын
The BEAM erlang vm basically
@HectorGonzalez-vp1ss
@HectorGonzalez-vp1ss 2 жыл бұрын
Thank you!
@jackmiddleton2080
@jackmiddleton2080 2 жыл бұрын
You talk a lot about connection limits but I would have thought the main limiting factor would be how much traffic is going back and forth in the open connection.
@dashiellbark-huss6806
@dashiellbark-huss6806 2 жыл бұрын
awesome explanation
@ozdemirsalik
@ozdemirsalik Жыл бұрын
Websockets are scalable. Just use multiple of them. And keep a database for which user group is using which socket. That’s how I solved it in my application.
@mihastifler
@mihastifler Жыл бұрын
Websockets are pretty scalable, just for some solutions using them is not best for scaling and some is best for scaling. The only thing you have worry about is tcp sockets.
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 Жыл бұрын
New Java feature introduced in Java 18 as a virtual thread makes websockets very scalable, you can run hundred of thousands thread without a problem.
@132_priyankrai5
@132_priyankrai5 Жыл бұрын
topics like webSockets, server sent events are hard to find and it's a mess in your channel make special playlist for talking about strategies
@siyaram2855
@siyaram2855 2 жыл бұрын
Really? Discord scaled 5million concurrent connections on web sockets
@codedamn
@codedamn 2 жыл бұрын
Did you not watch the video?
@siyaram2855
@siyaram2855 2 жыл бұрын
@@codedamn Thanks for the swift reply 🙏 I did. Can you shed some light how they did it?
@surajvijay1937
@surajvijay1937 2 жыл бұрын
There is actually a blog written by discord's cto where he mentioned about this along with why and how they migrated from mongodb to cassandra
@siyaram2855
@siyaram2855 Жыл бұрын
@@surajvijay1937 thanks
@Raj-iz9uz
@Raj-iz9uz 2 жыл бұрын
International Level Content only available in Indian Tech "Codedamn" Channel 🔥🔥🔥
@vivkrish
@vivkrish 2 жыл бұрын
You probably missed the part when the server connects to the client.
@AkashSide
@AkashSide 2 жыл бұрын
Awesome video
@DuyTran-ss4lu
@DuyTran-ss4lu 2 жыл бұрын
Great
@LuthandoMaqondo
@LuthandoMaqondo 2 жыл бұрын
If I'm to have a solution that's not cloud based, I would use SSE's for as long as the event period is at least three seconds.
@EliSmith
@EliSmith 2 ай бұрын
This is not a good solution, it doesn't apply to on prem infrastructure.
@YaadhumAanavan
@YaadhumAanavan Жыл бұрын
Marker cap moved from little finger to ring finger @9.57
@VishalKumar-fw5fz
@VishalKumar-fw5fz 2 жыл бұрын
Please make a video on message broker
@hindistories4312
@hindistories4312 2 жыл бұрын
amazing video
@everythingjdm8057
@everythingjdm8057 9 ай бұрын
Just use long polling
@keivansf3459
@keivansf3459 2 жыл бұрын
thanks
@sayanmdn
@sayanmdn Жыл бұрын
All good but one thing COST.
@gofudgeyourselves9024
@gofudgeyourselves9024 2 жыл бұрын
Ajinkya Rahane
@ramitsharma3773
@ramitsharma3773 2 жыл бұрын
Good knowledge. BTW, my T shirt size is L :)
@ridl27
@ridl27 2 жыл бұрын
ty
@sandworm9528
@sandworm9528 Жыл бұрын
JESUS CHRIST. Shut the music down.
@HSBTechYT
@HSBTechYT 2 жыл бұрын
Miss your videos
@Avoid0
@Avoid0 2 жыл бұрын
Wow 🔥
@ducodarling
@ducodarling Жыл бұрын
You basically just proved why websockets are horizontally scalable. Amazon isn't using magic, you know. They just have a bunch of computers.
@shivamsahi8160
@shivamsahi8160 4 ай бұрын
i need this tshirt
@KnowledgeUnknown
@KnowledgeUnknown 2 жыл бұрын
I dont want t shirt i want more knowledge 💥💥 thankyou sir
@code_community
@code_community 2 жыл бұрын
"codedamn" are damn Crazy 🔥
@kartikhira9217
@kartikhira9217 Жыл бұрын
Nice. Now give me a T-Shirt
@lakshman587
@lakshman587 2 жыл бұрын
COMMENTED FOR T SHIRT GIVEAWAY!!!! :)
@hillstudios1
@hillstudios1 2 жыл бұрын
You never said how to scale it??.What if my app gets used by millions of people everyday
@fdg-rt2rk
@fdg-rt2rk Жыл бұрын
Use Erlang
@stormrider22
@stormrider22 Жыл бұрын
Redis.
@shrine010
@shrine010 Жыл бұрын
So many minutes to conclude into stupid cloud.
@brucebane7401
@brucebane7401 Жыл бұрын
🔥🔥
How to scale WebSockets to millions of connections
14:01
Ably Realtime
Рет қаралды 23 М.
What are WebSockets? How is it different from HTTP?
8:47
Mehul - Codedamn
Рет қаралды 81 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 27 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 43 МЛН
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 5 МЛН
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 8 МЛН
What is NGINX and how reverse proxies work?
10:16
Mehul - Codedamn
Рет қаралды 69 М.
WebSockets Crash Course - Handshake, Use-cases, Pros & Cons and more
47:33
What is Cross Origin Resource Sharing? Never Get CORS Errors Again
8:36
Mehul - Codedamn
Рет қаралды 15 М.
What is WebSocket? Why is it used & how is it different from HTTP?
33:23
NGINX Tutorial - What is Nginx
14:32
TechWorld with Nana
Рет қаралды 88 М.
Do NOT Learn Kubernetes Without Knowing These Concepts...
13:01
Travis Media
Рет қаралды 267 М.
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 615 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 27 МЛН