Why WebSockets Are NOT Scalable | WebSockets Explained

Поділитися
Вставка
  • Опубліковано 1 жов 2024

КОМЕНТАРІ • 100

  • @codedamn
    @codedamn  3 роки тому +2

    Learn WebSockets and other Full Stack Technologies on codedamn: cdm.sh/fullstack

    • @Animelover-ds9vg
      @Animelover-ds9vg 3 роки тому

      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 Рік тому +18

    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.

  • @johnboy14
    @johnboy14 Рік тому +4

    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.

  • @jwbonnett
    @jwbonnett Рік тому +26

    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 Рік тому +5

      This is the right answer. The solution in this video isn't a good one

    • @the_maroon_knight
      @the_maroon_knight Рік тому +1

      I am really confused by this one. Is there any resource from which I can actually read this up?

    • @iamcrabgod2809
      @iamcrabgod2809 9 місяців тому

      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 7 місяців тому +1

      @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: ua-cam.com/video/vXJsJ52vwAA/v-deo.html

  • @cschandragiri
    @cschandragiri Рік тому +5

    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

  • @brgautam
    @brgautam 3 роки тому +13

    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  3 роки тому +3

      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 3 роки тому +7

      @@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.

  • @TheHellishFrog
    @TheHellishFrog 6 місяців тому +1

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

  • @HimanshuChoudhary-smartfire
    @HimanshuChoudhary-smartfire 3 роки тому +18

    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 Рік тому +3

      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 Рік тому +1

      ​@@reprovedcandy then, what is alternative?

  • @JavierMonsuarez
    @JavierMonsuarez 2 роки тому +3

    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

  • @sandworm9528
    @sandworm9528 2 роки тому +1

    JESUS CHRIST. Shut the music down.

  • @sarathkumarm7221
    @sarathkumarm7221 7 днів тому

    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.

  • @staplepin8099
    @staplepin8099 2 роки тому +2

    ERLANG VM entered the chat 🤣

  • @terasoft-official
    @terasoft-official 2 роки тому +1

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

  • @rdesouza82
    @rdesouza82 3 роки тому +3

    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 роки тому +1

      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.

  • @stemateflorentin1715
    @stemateflorentin1715 2 роки тому +4

    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.

  • @ajsyt
    @ajsyt 3 роки тому +3

    2:21 Until the world runs out of silicon 😂

  • @marvelfancollection3690
    @marvelfancollection3690 3 місяці тому

    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.

  • @itskishank
    @itskishank 4 місяці тому

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

  • @braintricker_soft
    @braintricker_soft 7 місяців тому

    Use message broker to publish message centrally to every instance of web socket server

  • @EliSmith
    @EliSmith 4 місяці тому

    This is not a good solution, it doesn't apply to on prem infrastructure.

  • @marvelfancollection3690
    @marvelfancollection3690 3 місяці тому

    Bro you can vertical..the the idea is spread the load over the ports

  • @KevinBoutin
    @KevinBoutin Рік тому +1

    Serverless will absolutely allow horizontally scaling of web sockets. Each message is dispatched to a serverless function for processing.

  • @avirads
    @avirads 3 місяці тому

    great explanation. thanks.

  • @SleepeJobs
    @SleepeJobs 3 роки тому +2

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

  • @akash-kumar737
    @akash-kumar737 2 роки тому +1

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

  • @smaranh
    @smaranh 3 роки тому +1

    Another alternative is switching to gRPC which can provide bidirectional communication.

  • @KrishnenduKDG
    @KrishnenduKDG 3 роки тому +1

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

  • @shrine010
    @shrine010 Рік тому

    So many minutes to conclude into stupid cloud.

  • @sayanmdn
    @sayanmdn Рік тому

    All good but one thing COST.

  • @keshavmishra2397
    @keshavmishra2397 3 роки тому +6

    Your content is always amazing!

  • @everythingjdm8057
    @everythingjdm8057 10 місяців тому

    Just use long polling

  • @shivamsahi8160
    @shivamsahi8160 5 місяців тому

    i need this tshirt

  • @djangbahevans1
    @djangbahevans1 10 місяців тому

    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.

  • @hemantkawale6945
    @hemantkawale6945 Рік тому

    Great video.

  • @stream8k
    @stream8k Рік тому

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

  • @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.

  • @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 3 роки тому +1

    Really?
    Discord scaled 5million concurrent connections on web sockets

    • @codedamn
      @codedamn  3 роки тому +1

      Did you not watch the video?

    • @siyaram2855
      @siyaram2855 3 роки тому +1

      @@codedamn Thanks for the swift reply 🙏
      I did.
      Can you shed some light how they did it?

    • @surajvijay1937
      @surajvijay1937 2 роки тому +1

      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 2 роки тому

      @@surajvijay1937 thanks

  • @YaadhumAanavan
    @YaadhumAanavan Рік тому

    Marker cap moved from little finger to ring finger @9.57

  • @yoddeb
    @yoddeb Рік тому

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

  • @santhoshk9285
    @santhoshk9285 3 роки тому +2

    codedamn forever 🔥

    • @codedamn
      @codedamn  3 роки тому +1

      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.

  • @DuyTran-ss4lu
    @DuyTran-ss4lu 3 роки тому +1

    Great

  • @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.

  • @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.

  • @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.

  • @Raj-iz9uz
    @Raj-iz9uz 3 роки тому

    International Level Content only available in Indian Tech "Codedamn" Channel 🔥🔥🔥

  • @soorajs577
    @soorajs577 3 роки тому

    Yesterday I faced cores issue. UA-cam 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

  • @ramitsharma3773
    @ramitsharma3773 3 роки тому

    Good knowledge. BTW, my T shirt size is L :)

  • @lakshman587
    @lakshman587 3 роки тому

    COMMENTED FOR T SHIRT GIVEAWAY!!!! :)

  • @vivkrish
    @vivkrish 2 роки тому

    You probably missed the part when the server connects to the client.

  • @KnowledgeUnknown
    @KnowledgeUnknown 3 роки тому

    I dont want t shirt i want more knowledge 💥💥 thankyou sir

  • @code_community
    @code_community 2 роки тому

    "codedamn" are damn Crazy 🔥

  • @akshaygadekar9926
    @akshaygadekar9926 3 роки тому

    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....

  • @LuthandoMaqondo
    @LuthandoMaqondo 3 роки тому

    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.

  • @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.

  • @vinayakbhat8495
    @vinayakbhat8495 Рік тому

    Good explanation. Thanks!

  • @aj35lightning
    @aj35lightning 3 роки тому +1

    doesn't phoenix channels use very horizontally scaleable websockets?

  • @HSBTechYT
    @HSBTechYT 2 роки тому

    Miss your videos

  • @kartikhira9217
    @kartikhira9217 Рік тому

    Nice. Now give me a T-Shirt

  • @shrestha0144
    @shrestha0144 3 роки тому

    Every time i get notified of your video, i come here as soon as I can

  • @Sonu-tg6tg
    @Sonu-tg6tg 3 роки тому

    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!!

  • @hillstudios1
    @hillstudios1 2 роки тому

    You never said how to scale it??.What if my app gets used by millions of people everyday

  • @SushilKumar-ig8ls
    @SushilKumar-ig8ls 3 роки тому

    Thank you for giving solutions to problems. It was really a good concept to understand and know.

  • @arvindshelke8889
    @arvindshelke8889 3 роки тому

    Thanks, i was trying to learn sockets, it helps!

  • @md.hasanmahmudrimon9867
    @md.hasanmahmudrimon9867 2 роки тому

    Your information is much appreciated

  • @VishalKumar-fw5fz
    @VishalKumar-fw5fz 3 роки тому

    Please make a video on message broker

  • @melwin217
    @melwin217 3 роки тому

    Is this related to system design?

  • @dashiellbark-huss6806
    @dashiellbark-huss6806 2 роки тому

    awesome explanation

  • @sghayeroumayma8506
    @sghayeroumayma8506 2 роки тому

    This is great! thank you.

  • @alex_ventura
    @alex_ventura 2 роки тому

    Great video!

  • @AkashSide
    @AkashSide 3 роки тому

    Awesome video

  • @keivansf3459
    @keivansf3459 2 роки тому

    thanks

  • @Avoid0
    @Avoid0 3 роки тому

    Wow 🔥

  • @AvigyanBhakta
    @AvigyanBhakta 3 роки тому

    Real good explanation 👍

  • @hindistories4312
    @hindistories4312 3 роки тому

    amazing video

  • @HectorGonzalez-vp1ss
    @HectorGonzalez-vp1ss 3 роки тому

    Thank you!

  • @ridl27
    @ridl27 3 роки тому

    ty

  • @brucebane7401
    @brucebane7401 Рік тому

    🔥🔥

  • @gofudgeyourselves9024
    @gofudgeyourselves9024 3 роки тому +1

    Ajinkya Rahane