8
votes

Does AWS natively support weighted load balancing?

From what I see, ELB does only support round-robin load balancing (without any configurable weights). I have not found reliable documentation on it, though.


The easiest thing that I can think of is to put a load balancer like Nginx in front of it, for example:

upstream backend  {
  server backend1.example.com weight=1;
  server backend2.example.com weight=2;
  server backend3.example.com weight=4;
}

Here, out of seven requests, one will go to backend1, two to backend2, and four to backend4.

It will work, but it also means you have to setup a server with Nginx just for that. If AWS would directly support weighted load balancing that would be far easier to setup.

4
You are totally right. AWS ELB per se only works with round robin. See the Routing Algorithm section of this documentationimTachu
There is no difference in that regard between the Classic Load Balancer and the new Application Load Balancer, is there?Philipp Claßen
In that regard no. The main difference is that the ELB detects unhealthy instances and routes traffic only to healthy instances, but they both use round-robin.imTachu

4 Answers

8
votes

The How Elastic Load Balancing Works documentation page states:

With a Classic Load Balancer, the load balancer node that receives the request selects a registered instance using the round robin routing algorithm for TCP listeners and the least outstanding requests routing algorithm for HTTP and HTTPS listeners.

With an Application Load Balancer, the load balancer node that receives the request evaluates the listener rules in priority order to determine which rule to apply, and then selects a target from the target group for the rule action using the round robin routing algorithm. Routing is performed independently for each target group, even when a target is registered with multiple target groups.

The Elastic Load balancing service does not support weighted round-robin (where you specify the weights).

You could use Amazon Route 53 with a Weighted Routing Policy. From the Choosing a Routing Policy documentation page:

Use the weighted routing policy when you have multiple resources that perform the same function (for example, web servers that serve the same website) and you want Amazon Route 53 to route traffic to those resources in proportions that you specify (for example, one quarter to one server and three quarters to the other).

5
votes

UPDATE BASED ON NEW FEATURES FROM AWS

Originally, you were not able to do weighted routing on a LoadBalancer. However, that has recently changed

If you are using an Application Load Balancer, it is possible to set a ListenerRule which will use a weighted policy.

Steps:

  1. Create your Load Balancer
  2. Add a Listener onto your Load Balancer
  3. Add a Listener Rule onto your Listener
  4. Add a policy that forwards traffic based on whatever IF statement you need
  5. You now have the option to add multiple target groups, add these and assign a weighted amount to each.

You can see the AWS blog post that highlights this here: https://aws.amazon.com/blogs/aws/new-application-load-balancer-simplifies-deployment-with-weighted-target-groups/

3
votes

You could use Route53 weight routing directly to your servers or to multiple ELBs

3
votes

If you are using AWS Route 53 as DNS service, you can configure the weight-age on DNS record.

DNS weight-age refer 2.2

Amazon Route 53 support Weighted Round Robin. Weighted Round Robin allows you to assign weights to resource record sets in order to specify the frequency with which different responses are served. You may want to use this capability to do A/B testing, sending a small portion of traffic to a server on which you’ve made a software change. For instance, suppose you have two record sets associated with one DNS name—one with weight 3 and one with weight 1. In this case, 75% of the time Route 53 will return the record set with weight 3 and 25% of the time Route 53 will return the record set with weight 1. Weights can be any number between 0 and 255.