What is load balancing


Simply a load balancer is a device or software that distribute incoming network traffic across multiple servers to ensure High availability (HA), efficiency and reliability of the application.

If one server goes down the load balancer route traffic to available other servers, this eliminates the single point of failure and if a new server was added to the system, load balancer starts serving traffic through it.

Let's see a simple web application without load balancing




In the above typical example, User connects with the web-server directly through the internet, if the single web-server goes down, the user no longer will be able to use the application. This is a single point of failure.
Also if the network load is too high which cannot handle to a single server, the users may experience low response time or system might crash at some point.

Now to overcome the above issues, load balancers were introduced.


The request from user now will be forwarded to the load balancer and then to the selected backend server. These servers maintain similar state to avoid sending back inconsistent data back to the user.
Now even one server goes down, the load balancer will route traffic to the available server, but still, there is a single point of failure which is the load balancer itself.
This can be overcome by introducing another load balancer.

Types of load balancers

1) Hardware 
Hardware load balancer is a physical device which use to route network traffic to servers based on server status like resource utilization, no of connection to the server etc. 
HLB is in Layer 4 (Transport) and Layer 7 (Application) OSI model. Layer 4 servers are used for tunneling and routing. Layer 7 servers are used to form a delivery network.
Eg:  F5

2) Software
Software load balancer is a piece of software that installed and configure to a server to perform load balancing.
Eg: Nginx, HAproxy, Varnish

Load balancers only forward traffic to healthy backend servers. Health checks are regularly run to monitor the health of a backend server. Basically what a health check does is checking the backend servers are listening.

Load balancing algorithms

Load balancing algorithms decide the logic behind routing the traffic, below are few popular algorithms used to load balancing.
  • Round Robin
For the first request, the Load Balancer picks the first server from the server list then move down in the order. This runs sequentially.
  • Least Connection
As the name suggests it selects the server with the least connections.
  • Source/Ip hash
In source load balancing is determined by the client/source IP address using the hash of the IP address. 

Conclusion

This blog post is about the fundamentals of the load balancing, this will help you to explore more and understand the basics.


Let's meet how to set up and do a simple load balancing in the next blog post :)

Thank you

Comments