Updated on 2022-01-25 GMT+08:00

How ELB Works

To balance the load of your applications, you need to 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 a listener to it and associate at least one backend server with it. The load balancing algorithm you select when you add the listener determines how requests are distributed.

ELB supports 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 often used for short connections, such as HTTP connections.
  • 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 often 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.

The following figure shows an example of how requests are distributed using the weighted round robin algorithm. Four backend servers have the same weight, and each server receives the same proportion of requests.

Figure 1 Traffic distribution using the weighted round robin algorithm