When we see websites, we see a single server responding to requests from various users. Which is very much true for most websites. But some websites receive a lot of incoming traffic. They are serving hundreds of thousands of users at any given moment, These kinds of websites cannot be served from a single server, no matter how powerful it is. This is where Load Balancing comes into the picture.
What is Load Balancing?
The easiest explanation for load balancing would be the mechanism by which total load on a system is distributed amongst a number of systems. Load Balancing allows you to distribute the incoming requests among several identical servers so that no single server gets overloaded. This results in faster processing of requests. Load Balancing is made possible with the help of specialized solutions called Load Balancers.
What are Load Balancers?
Load Balancers are equipment that implements load balancing. They are often the first point of contact for a request made to a server. Load balancers monitor and keep track of the health of each server in the cluster. There are 2 basic types of Load Balancers, software and hardware backed.
Software Backed Load Balancer
The software backed load balancers are usually installed on one of the servers themselves. Usually, server management software like Apache or Nginx are used as software load balancers.
People with exposure to Amazon Web Services would know about some good features offered by it. Since server costs are high, these load balancers make it easy to add or remove servers, scale up or down depending upon the amount of load on the site.
Hardware Backed Load Balancer
Hardware backed load balancers are real physical devices that are manually connected to each server in the cluster. They have proprietary software which is installed by the manufacturer itself. Such load balancers often run on specialized processors and other hardware that are designed for load balancing only.
Load Balancing Algorithms
Needless to say, load balancing doesn’t work on its own, there are several different algorithms and techniques that can be used to optimize load balancing. Some of them are as follows.
- Round Robin
In Round Robin, each server is given a request and every new request is given to the next server. This ensures that all servers receive the same number of requests.
- Least Connection
In the least Connection methods, the balancer checks for the server that has the least number of services, currently being served. The one with the lowest number of connections is given the request.
- Weighted Response Time
This method keeps track of the response times of all servers. Naturally, since all servers offer identical services, the one with the lowest response time is not under too much load. This type of server can be given the next request.
- Source IP Hash
Ip hashing creates a unique hash based on the IP address of the client and the server. This hash is used to make sure that a client’s requests are served by the same server for the entire session. This is very helpful in cases where session information for a user is stored on a particular server.
Load balancing becomes extremely important once your website begins to scale. It helps you effectively scale your services. Several good load balancing mechanisms already exist that make the job easier. I hope you have a basic understanding of what load balancing is and what role it can play in scaling a website or app. If you still have a doubt, do let me know in the comments section below.