Load Balancing Algorithms
Learn some common algorithms for load balancing.
How do LBs balance the load?
There are several load balancing algorithms that are commonly used in the industry. Let’s discuss the algorithms in two categories: application-layer algorithms and network-layer algorithms.
Application-layer algorithms
In application-layer load balancing, the load balancer has access to the data of the request. It can take decisions based on the request headers as well as the request body. Let’s discuss popular application-layer load balancing algorithms.
Hashing
A common application-layer algorithm is hashing. The LB can hash a set of predefined attributes and generate a hash value. The hash value is then mapped to one of the server nodes. Let’s give a simple example.
Assume that the request body from a client contains a user_ID
. Upon receiving the request, the LB can do the following steps
- Hash the
user_ID
using any pre-configured hash function. Say foruser_ID = abc123
, the hash function returns a value981723123
. - Take the returned value and map it to a server node. This can be done by using the modulo operation
981723123 % 5
which equals3
. Here, we are taking a modulo by5
as this is the count of nodes in the system. - Route the request to node
3
.
Get hands-on with 1400+ tech skills courses.