AWS Elastic Load Balancer and multiple availability zones

12,832

Solution 1

If you enable ELB Cross-Zone Load Balancing, d1 will get 20% of the traffic.

Here's what happen without enabling Cross-Zone Load Balancing: D1 would get nearly 50% of the traffic. This is why Amazon recommends adding the same amount of instances from each AZ to your ELB.

The following excerpt is extracted from Overview of Elastic Load Balancing:

Incoming traffic is load balanced equally across all Availability Zones enabled for your load balancer, so it is important to have approximately equivalent numbers of instances in each zone. For example, if you have ten instances in Availability Zone us-east-1a and two instances in us-east-1b, the traffic will still be equally distributed between the two Availability Zones. As a result, the two instances in us-east-1b will have to serve the same amount of traffic as the ten instances in us-east-1a. As a best practice, we recommend you keep an equivalent or nearly equivalent number of instances in each of your Availability Zones. So in the example, rather than having ten instances in us-east-1a and two in us-east-1b, you could distribute your instances so that you have six instances in each Availability Zone.

Solution 2

The load balancing between different availability zones is done via DNS. When a DNS resolver on the client asks for the IP address of the ELB, it gets two addresses. And chooses to use one of them (usually the first). The DNS server usually responds with a random order, so the first IP is not used at all times but each IP is used only part of the time (half for 2, third of the time for 3, etc ...).

Then behind these IP addresses you have an ELB server in each availability zone that has your instances connected to it. This is the reason why a zone with just a single instance will get the same amount of traffic as all the instances in another zone.

When you get to the point that you have a very large number of instances, ELB can decide to create two such servers in a single availability zone, but in this case it will split your instances for it to have half (or some other equal division) of your instances.

Share:
12,832
mbsheikh
Author by

mbsheikh

Software Engineer @ EA

Updated on June 11, 2022

Comments

  • mbsheikh
    mbsheikh almost 2 years

    I want to understand how ELB load balances between multiple availability zones. For example, if I have 4 instances (a1, a2, a3, a4) in zone us-east-1a and a single instance d1 in us-east-1d behind an ELB, how is the traffic distributed between the two availability zones? i.e., would d1 get nearly 50% of all the traffic or 1/5th of the traffic?

  • Ville Mattila
    Ville Mattila over 11 years
    In case of availability zone failure, is all the traffic still routed to the ELB in failed AZ until client's DNS records are updated? So one ELB IP is not able to route traffic to instances at another AZ?
  • Evgeny
    Evgeny over 11 years
    If the zone is failed for some reason that affects instances, in most cases the ELBs will not work as well. It would be great if something that does not work or does not exist will route traffic to another place that does work, but unfortunately that is just wishful thinking.
  • Ville Mattila
    Ville Mattila over 11 years
    Indeed... ;) I was just thinking if the ELBs were located outside any specific AZ, "at region level", as the image in their documentation shows: docs.amazonwebservices.com/ElasticLoadBalancing/latest/… . This would allow routing requests to another AZ too.
  • Pawel Furmaniak
    Pawel Furmaniak over 9 years
    This answer is outdated.
  • TJ Biddle
    TJ Biddle over 9 years
    @uszywieloryba Please provide more information on why if this is the case.
  • Oded Breiner
    Oded Breiner almost 7 years
    This is very crucial to turn on when using Elastic Beanstalk, thanks!