How ELB Works
To balance the load of your applications, create a load balancer to receive requests from clients and route the requests to backend servers in one or more AZs. After the load balancer is created, you must add at least one listener to it and associate one backend server with it. The load balancing algorithm you select when you add the listener determines how requests are distributed.
Shared and dedicated load balancers support the following load balancing algorithms:
- Weighted round robin: Requests are distributed across backend servers in sequence based on their weights. Backend servers with higher weights receive proportionately more requests, whereas equal-weighted servers receive the same number of requests. This algorithm is typically used for short connections, such as HTTP connections.
The following figure shows an example of how requests are distributed using the weighted round robin algorithm. Two backend servers are in the same AZ and have the same weight, and each server receives the same proportion of requests.
Figure 1 Traffic distribution using the weighted round robin algorithm
- Weighted least connections: This algorithm is designed based on the least connections algorithm that uses the number of active connections to each backend server to make its load balancing decision. In addition to the number of connections, each server is assigned a weight based on its capacity. Requests are routed to the server with the lowest connections-to-weight ratio. This algorithm is typically used for persistent connections, such as database connections.
The following figure shows an example of how requests are distributed using the weighted least connections algorithm. Two backend servers are in the same AZ and have the same weight, 100 connections have been established with backend server 01, and 50 connections have been connected with backend server 02. New requests are preferentially routed to backend server 02.
Figure 2 Traffic distribution using the weighted least connections algorithm
- Source IP hash: The source IP address of each request is calculated using the consistent hashing algorithm to obtain a unique hash key, and all backend servers are numbered. The generated key allocates the client to a particular server. This allows requests from different clients to be routed based on source IP addresses and ensures that a client is directed to the same server that it was using previously. This algorithm works well for TCP connections of load balancers that do not use cookies.
The following figure shows an example of how requests are distributed using the source IP hash algorithm. Two backend servers are in the same AZ and have the same weight. If backend server 01 has processed a request from IP address A, the load balancer will route new requests from IP address A to backend server 01.
Figure 3 Traffic distribution using the source IP hash algorithm
- Connection ID: The connection ID in the packet is calculated using the consistent hash algorithm to obtain a specific value, and backend servers are numbered. The generated value determines to which backend server the requests are routed. This enables requests with different connection IDs to be routed and ensures that requests with the same connection ID are routed to the same backend server. This algorithm applies to requests to applications that use QUIC as the protocol.
Currently, only dedicated load balancers support the Connection ID algorithm.
The following figure shows an example of how requests are distributed using the connection ID algorithm. Two backend servers are in the same AZ and have the same weight. If backend server 01 has processed a request from client A, the load balancer will route new requests from client A to backend server 01.
Figure 4 Traffic distribution using the connection ID algorithm
- Round robin: Requests are distributed sequentially across all servers, so that the load is evenly shared. This algorithm is typically used for short connections, such as HTTP connections.
- Least connections: a dynamic scheduling algorithm that estimates backend server load based on the number of active connections. Requests are routed to servers with the minimum number of connections. This algorithm is typically used for persistent connections, such as database connections.
- Source IP hash: The source IP address of each request is calculated using the consistent hashing algorithm to obtain a unique hash key, and all backend servers are numbered. The generated key allocates the client to a particular server. This allows requests from different clients to be routed based on source IP addresses and ensures that a client is directed to the same server that it was using previously. This algorithm works well for TCP connections of load balancers that do not use cookies.
Factors Affecting Load Balancing
In addition to the load balancing algorithm, factors that affect load balancing generally include connection type, session stickiness, and server weights.
Assume that there are two backend servers with the same weight (not zero), the weighted least connections algorithm is selected, sticky sessions are not enabled, and 100 connections have been established with backend server 01, and 50 connections with backend server 02.
When client A wants to access backend server 01, the load balancer establishes a persistent connection with backend server 01 and continuously routes requests from client A to backend server 01 before the persistent connection is disconnected. When other clients access backend servers, the load balancer routes the requests to backend server 02 using the weighted least connects algorithm.
If backend servers are declared unhealthy or their weights are set to 0, the load balancer will not route requests to the backend servers.
For details about the weighted least connections algorithm, see Load Balancing Algorithms.
If requests are not evenly routed, troubleshoot the issue by referring to How Do I Check Whether Traffic Is Evenly Distributed?
Last Article: Specifications of Dedicated Load Balancers
Next Article: Public or Private Network Load Balancing
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.