I'm managing a service with long-lived WebSocket connections, and I'm facing a challenge. Once I reach my configured capacity, I'd like to stop my Application Load Balancer (ALB) from routing new traffic to one of my instances. I've attempted to use separate live and ready endpoints, but when the ready endpoint indicates degraded performance, it gets drained and rescheduled, which isn't ideal. Has anyone implemented a solution for handling traffic routing like this?
4 Answers
Another route could be using the "Least outstanding requests" routing algorithm in your target group. This way, requests go to the instances that have the lowest number of in-progress requests. But remember, this mainly benefits initial connections, not ongoing WebSocket connections.
You might want to consider just having the properly sized instances for your traffic needs. If you must implement a temporary stop, one option could be for the instance to remove itself from the target group when it hits capacity and then reinsert itself when it's ready again.
Why not utilize a Lambda function to manage your ALB security group? By adding or removing ports, you could stop traffic from being routed without terminating existing connections.
You could also set up your ALB health checks to fail when you reach capacity and pass when below capacity. This should work fine with EC2 instances and would effectively stop new traffic.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures