Best practices for websocket deployment

0

We have built a websocket system for our requirement and will be deploying it on AWS EC2.

I am looking for best practices in terms of load-balancing. We are thinking of having ALB to front the websocket server nodes. We expect to get around 50,000 connections initially and most likely will have 3 websocket servers deployed.

  • What are the best practices / configurations on ALB for this?
  • We will also be having API servers on EC2. Should we share the same ALB or have different ALB set up for websocket and API?
  • Is there a way to configure the load-balancing based on connection-count?
  • In case a websocket server restarts/goes down, our assumption is that ALB will also disconnect all the clients and they are expected to reconnect on their own. Is this correct?
spy16
asked 4 months ago257 views
3 Answers
0
Accepted Answer

Customize health checks to accurately reflect server load and capacity. Default health checks might not be suitable for WebSocket connections which primarily rely on I/O operations. https://aws.amazon.com/blogs/compute/using-websockets-and-load-balancers-part-two/

Set up ALB listeners properly. Listeners are essential for handling incoming connection requests. You must define at least one listener for your ALB to manage traffic. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html

Utilize forwarding actions and weighted target groups to distribute traffic. You can route requests to multiple target groups with assigned weights, influencing how traffic is distributed among them. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html

Be aware that ALBs don't immediately detect an unhealthy node. If a WebSocket server restarts or goes down, the ALB may continue routing connections to it until it is marked unhealthy. https://aws.amazon.com/blogs/compute/using-websockets-and-load-balancers-part-two/

ALBs provide metrics like NewConnectionCount, representing the total number of new TCP connections established, and RejectedConnectionCount, indicating connections rejected due to the load balancer reaching its maximum connection limit. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html#:~:text=,the%20load%20balancer%20to%20targets

You may want to use different ALBs for WebSocket and API servers, depending on your architecture and traffic patterns. This can provide greater management and tuning according to the needs of each service.

profile picture
EXPERT
answered 4 months ago
profile picture
EXPERT
reviewed 4 months ago
0

Hi,

this post describes the best practices re. load-balancing and websockets when using LightSail: https://aws.amazon.com/blogs/compute/using-websockets-and-load-balancers-part-two/

Best,

Didier

profile pictureAWS
EXPERT
answered 4 months ago
0

Thank you all ! I will take a look at these resources.

spy16
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions