What is Load Balancing?
This is an article discussing the basics of load balancing - what it is and how it's helpful.
Hello readers,
Hope you’re doing well. In this edition, I will help you explain the following points:
What is Load Balancing?
Why do we need Load Balancing?
Types of Load Balancing Algorithms
Conclusion
What is Load Balancing?
Load balancing is a technique used for distributing your incoming network traffic to a group of servers in an efficient way. The load balancer is a device that sits between your users and your servers and majorly helps in doing the following:
Forward requests from your users to the servers
Ensures that all the server resources are properly utilized and no server is given traffic more than their capability
Provides the flexibility to add/remove the servers as the traffic goes high/low
Why do we need Load Balancing?
Imagine you’re using the Instagram app. Now since Instagram is so popular and used globally, it cannot fulfill all the user or client requests through one server only. So, there is a clear need to use multiple servers.
Load Balancing technique or the use of a Load Balancer helps us with the following:
Application Availability: If there are multiple servers and any one (or group of) server start failing, it might cause a degraded experience and your application would become unavailable to a cohort of users. Load balancer helps in monitoring the health and performance of the servers and stops sending live traffic to the degraded servers, thus increasing the availability of your application.
Application Scalability: With increased traffic, there might be new servers(on-demand) spawned for handling the traffic and sustaining the customer experience. Load balancer helps in intelligently routing the live traffic to the existing and new servers to live up to the user experience expectations. Thus, you can scale up/down the number of servers depending on the traffic with no additional overhead.
Application Security: There might be some attackers who try to send an abnormally large number of requests to the servers also known as the DDOS attack. If you allow this huge number of requests to go to servers, the server might go down because of not being able to respond to such huge traffic. Load balancers help you monitor the traffic and block any suspicious users from sending further requests based on configured thresholds like the number of requests allowed per minute.
You can also configure some additional layers of firewall inside load balancers to provide an extra layer of security.Application Performance: Load balancers try to distribute the load evenly across multiple servers to get the best performance out of the overall application. An example to achieve this performance is by redirecting the client requests to a geographically closer area where servers are hosted to reduce the overall network latency in getting the response.
Thus, as discussed above load balancers are a critical component when handling a huge amount of traffic for your website/application and providing the right customer experience.
Types of Load Balancing Algorithms
Since we’ve understood that there is a need for load-balancing the incoming traffic for a healthy distribution among the server group, it’s important to understand the different types of load-balancing algorithms that are present.
Following are some algorithms/strategies popularly known across the Tech industry
Round-Robin: This algorithm forwards incoming client requests to each server one at a time. Let’s say there are 10 requests incoming and there are 5 servers. Then, Request 1 goes to Server 1, Request 2 goes to Server 2, Request 3 goes to Server 3, Request 4 goes to Server 4, Request 5 goes to Server 5, Request 6 goes to Server 1, Request 7 goes to Server 2, and so on.
This algorithm does not take into account that there might be different servers of different capacity/power( like CPU, Storage, etc) and thus is not a very ideal approach to do load balancing.Weighted Round-Robin: You can assign different weights (like a numeric integer) to each of the servers based on the priority and the capacity of the server. Servers with higher weights will receive more incoming application traffic and servers with less weights will receive less traffic.
This algorithm is good in a way that it helps you take into account the power of the server (like heavy CPU, more storage, etc) and thus is a good load-balancing algorithm.Hash-Based: The load balancer performs a hashing on top of any client’s parameter like IP address or Request URL and maps the resultant hash value to a particular server. This way, all the client requests go to one server or a group of servers (if we use Consistent Hashing).
Least-Connection: When any client sends any request to the server, then a connection is established between the two. In this method, the load balancer keeps the count of which server has how many active connections and routes the incoming traffic to the server with the fewest connections.
Weighted Least Connection: Similar to the weighted round-robin algorithm but with the least connections. This method forwards the client requests to the server depending on the following:
a) Assigned weight to the server and
b) Number of active connections with the server.
The server with the highest weight and least active connections will be preferred first for processing the incoming requests.Least Response Time: The server response time is the amount of time the server takes to process the incoming requests and return the response. This strategy combines the least response time of any server along with the least connections strategy to find the suitable server for incoming traffic.
Conclusion
Load balancing becomes a necessity at some point when you’re growing your audience/clients. If the service that you provide is reaching millions, you need multiple servers to handle this huge amount of traffic. For better handling or management of this traffic across multiple servers, you need to have a facilitator in between your users and servers that takes care of how your traffic is routed.
That’s it, folks. If you liked this edition of the newsletter, share it with your circle. Please consider liking this article and subscribing to this newsletter as it keeps motivating me to bring you good-quality content.
Resources
https://aws.amazon.com/what-is/load-balancing/
https://www.nginx.com/resources/glossary/load-balancing/
https://www.techtarget.com/searchnetworking/definition/load-balancing
We have too many algorithms for loadbalancing , which one is generally recommended. Or does the service provider which provides this facility take care of it. How do we determine that. Or does the devops team handle this
Hi Vivek, thanks for providing this brief yet quality content about load balancing. However though i have this dumb question is reverse proxy and load balancer are essentially the same?