4

Context: A Rails app running action cable for websockets using Redis, on an EC2 instance, about to be upgraded to work on multiple instances behind an AWS Application Load Balancer. I've read a few blogs explaining people's setup, but there's a key concept I'm not getting.

Question: My understanding of websockets is that they require a fixed connection between the browser and the server. AWS Application Load Balancer (ALB) handles this by fixing a websocket connection to a specific instance behind the ALB. But suppose someone is subscribed to a channel and has a connection through the ALB to server A, and an event happens on server B which triggers a websocket broadcast for that channel.

How do the clients connected to that channel on server A ever get the message?

John Small
  • 942
  • 2
  • 12
  • 21
  • 1
    as far as i know, Rails ActionCable use Redis pub/sub to broadcast messages, so it depends on how you setup Redis work with the load balancer. – Lam Phan Dec 12 '21 at 08:59
  • Yes. I was thinking I'd have to use AWS Elasticache with the Redis API, so that there's one single source of information. I'm guessing that if both servers A and B use a single Redis server, with ActionCable servers on both A and B then any message put in the server cache would be acted on by A and B, so that all subscribers would get the message. But I'm not sure how messages are dequeued. If server A picks up the message, can server B still see it? Or do I have to have one single Cable server, and Rails servers A and B can send messages to it to be published? – John Small Dec 13 '21 at 11:28
  • @JohnSmall did you ever find the answer? – DavidB Mar 21 '22 at 04:42
  • 1
    I switched to using our Postgresql database as the single point of contact for action cable. It's a simple option in the action cable config file. But that's because we don't have a lot of traffic. If you have a high traffic site then one of the AWS in memory databases would be the best way to go. But I didn't investigate as I got a solution that's good enough. – John Small Mar 22 '22 at 10:53

0 Answers0