Load Balancers, An Analogy

Vikneswaran
codeburst
Published in
5 min readJun 12, 2020

--

The load balancer is an essential component in distributed computing architecture. As the name suggests, the role of a load balancer is to distribute the incoming network traffic among the cluster of the distributed servers so that the work has been done by the single computer will be distributed among multiple computers which makes the process faster and highly available.

Load Balancer between client and the server.

Let's understand the load balancing with an analogy. Imagine a restaurant with only a single chef where he can cook dishes one by one based on the order placed. So that everyone needs to wait in a queue until the previous order gets completed. Initially, a single chef can handle the orders since the number of customers visiting the restaurant is less. But as the days go on the number of customers got increased which added the additional load on a single chef. To compensate for the additional load the restaurant recruits another two chefs to make the process faster. And let's assume the chefs are cooking independently and don't know about what the other chefs are cooking and the orders are taken by the chefs one by one in a round-robin manner.

But this process will lead to the following limitations

  • What if the items taken by one chef will take more time to cook than the other two? So again one will get more load than the other two and the process become slower.
  • What if one chef is on leave? So that his orders will get unnoticed since the chefs don't know about each other's work.
  • What if one chef is specialized in something whereas others don't know how to cook the same?
  • What if a restaurant recruits a new chef who is specialized only in particular dishes?
Photo by Michael Browning on Unsplash

To overcome the above limitation we need someone to supervises (monitor) the chef's activities to distribute the orders among the chefs. The supervisor of the restaurant will distribute the orders based on the chef's load, availability, specialization, and various other factors to make the process quicker. This is how a load balancer works in a distributed computing environment.

Load Balancer Features

Let's fit this analogy with some of the primary roles of actual load balancers.

  • As the name suggests once of the primary role of the load balancers is to distribute the incoming request among the servers based on the configured load balancing algorithm.
  • Actively monitoring the health of the servers in the cluster to ensure the server is live. If a server is down then the load balancers will stop forwarding the requests until the server becomes live which ensures the high availability, reliability.
  • Facilitates adding/removing servers dynamically from the clusters and it balances the load accordingly without impacting the existing servers based on the demand which improves the scalability.

Load Balancing Algorithms

In a distributed environment, there are various techniques used for load balancing. Let's understand some of the most command load balancing algorithms.

  • Round Robin - This is one of the basic load balancing technique where the request will be forwarded one by one to every server in the clusters sequentially. In practice, this method is rarely used.
  • Weighted Round Robin - This works the same as the round-robin method but additionally here each server in the cluster will be assigned a weight and the server which has assigned higher weights will get more traffic and the serves with lower weights will get lesser traffic.
  • Least connection - Here the server load is taken as a consideration. Among the cluster, the traffic will be directed to a server which has the least number of active sessions. The traffic is distributed based on the server load.
  • Weighted Least Connection - This is a weighted algorithm build on top of the Least connection technique. where each server in the cluster is assigned a weight. If two servers hold the same number of active sessions then the request will be directed to the server with higher weight.
  • Least Response Time Method - This algorithm directs traffic to the server which holds the least number of active connections and the lowest average response time.
  • Least Bandwidth Method - This algorithm consider the bandwidth of the server to directs the traffic that is currently serving the least amount of traffic measured in megabits per second (Mbps).
  • IP Hash - This algorithm computes the hash based on the IP address of the incoming request and forwards the request to a particular server based on the computed hash. This algorithm is very common in load balancing the caching systems (like consistent hashing).

Network and Application Load Balancers

Further load balancers are classified as L4(Transport layer) and L7(Application layer) load balancers based on the 7 layers OSI (Open Systems Interconnections) Model.

  • L4 Load balancers - L4 load balancer will operate at the Transport Layer(Layer 4) of the OSI model. The IP address of the incoming request and TCP port is only accessible from the network packets in Transport Layer(L4). So the L4 type load balancer operations are only restricted with the information of IP and TCP port of the incoming request.
  • L7 Load balancers - L7 load balancers, on the other hand, will operate on the Application Layer(Layer 7) of the OSI model. The application layer can provide access to a whole lot of data along with IP and TCP port. The L7 load balancers can access the HTTP header, HTTP form data, session ID .etc of the incoming request. This additional information makes L7 type load balancers more intelligent and it is very common among real-world distributed architectures.

Typically load balancers are the primary component of the distributed computing environment. But they can be a single point of failure. To overcome this, a secondary load balancer will be added to form a cluster. Where both load balancers will monitor the health of each other. If the primary load balancer fails, the secondary load balancer will be promoted as a primary load balancer automatically.

The load balancer will play a prominent role in real-world distributed architectures and helps in scaling and improves responsiveness and high availability.

--

--