Idea behind Load Balancer


Reading time: 30 minutes

Modern High traffic websites take a billion of requests at one time from different users and return the response in the form of either text,videos or images .We can see that the site delivers the content without any failures.

So, may be the question arise in our mind ,how the server deals with these large no of requests

And in the traditional client-server architecture,web application are deployed on the server.User send the request to the server and server sent back the response according to user's request.

But, wait a sec ,what will happen if the server goes down?

Answer to these questions ,is: -

Load Balancer ,Yes, load balancer, in this article we will see the load balancer, what is this how we can use it, and what are the benefits and how this all works?

Definition

Load Balancer is the component in distributed systems that spreads the incoming requests from the client to cluster of servers. This ensures that if one server goes down, the load balancer will redirect that request to any other server. So, it can maximize the responsiveness and availability of the application.

Load Balancer is placed between the clients and the server accepting incoming requests and distributing the traffic across multiple backend servers using different algorithms.
Load balancers can handle any type of traffic like https ,http,tcp or udp etc.

loadcreatedbalancer

Load Balancer can be used between:-

  1. Between the user and web server
  2. Web servers and the internal platform layer
  3. Between internal platform layer and the database

Load Balancer Performs the following functions:

  • Spread the user requests or network traffic efficiently across the multiple backend servers.
  • Sending the requests to those servers which are online,this ensures the higher availabity and reliability of the applications
  • Adding and removing the server depending on the demands.

Benefit Of Using Load Balancer :

  1. Reduced Downtime
  2. Scalable
  3. Redundancy
  4. Flexibility
  5. Efficiency
  6. Global Server Load Balancing

For a long time, a load balancer lived as hardware in the private data center. They are remarkably expensive and they are also non-trivial to configure. But now load balancer have evolved often refer to as Application Delivery Controller or
ADC's they now provide the additional capabilities like security and authentication on in light-weight flexible software package.

As we have discussed above load balancers use different algorithms to select the server to which the traffic to be sent:-

Before selecting the server, the load balancer checks the health. Means, Load balancer forward the traffics to only those servers which are healthy. To monitor the health of the backend server โ€œhealth checksโ€ regularly attempt to connect to backend servers to ensure that servers are listening. If the server fails the health check, it is automatically removed from the pool and traffic is not being forwarded until the server responds to the health checks again.

Let's discuss about the different types of Load balancing algorithms.

Different types of Load balancing Algorithms : -

  1. Least Response Time Method - send request to the server with the fewest active connections and the lowest average response time.

  2. Least Connection Method - directs the traffics to the server which has least active connections.

  3. Least Bandwidth Method - This method selects the server that is currently serving the least amount of traffic measured in megabits per second (Mbps).

  4. Round Robin - this methods selects the server from the list of server which is in turn ,forwards a request,then it selects second server and then third.If all server is being selected ,it loops back and select the first server again.

  5. IP Hash - IP address of the client and the server is taken for generating a unique hash key. Key is used to designate the client to the particular server.

Load Balancers also maintain the user session across requests, this process is called session persistence. The client application usually stores the user's session information. This will be shared with the server. Load balancer needs to ensure that all requests from a client within a session are sent to the same server.

The Load Balancer can be software ,hardware or cloud-based types.

Popular Load Balancers in the market :

  • Nginx
  • Barracuda
  • TP-Link
  • Elastic Load Balancing from AWS
  • Cisco

What if the load balancer itself fails, then what will happen. A single instance of a load balancer would cause the whole system outage. So for dealing with these types of scenarios. A second load balancer can be connected to first to form a cluster
where each one monitors the others' health. Each one is equally capable of failure detection and recovery.

activepassiveload

Conclusion

Now, you know how the large enterprise deal with the million requests one time.

With this article at OpenGenus, you must have a good idea of Load balancing in general. Enjoy.