Cloud Development Services
Serverless Application development
Cloud Server deployments
Ahmedabad, IN
Visit Us!
Drop us a message!
Call us when you need!

Load Balancing Concepts for Beginners

Home - Web Optimization - Load Balancing Concepts for Beginners

Load Balancing Concepts for Beginners

Wondering what is Load Balancer and how it helps the business?

Load Balancing Concepts

In the era of dynamic web applications with numerous online competitors, it is extremely important to have a blazing fast website for your business. The website load time affects a business from multiple aspects.

  • Sale
  • Bounce rate
  • User experience
  • SEO ranking
  • Lead conversion

With a bunch of frameworks in the industry, it is becoming difficult to choose and go with a specific technology. However, the overall deployment and working of the website eventually remain the same. Thus, the high-level factors affecting the website speed are common.

One of the major factors affecting website speed is the traffic on the site. The increase in traffic eventually leads to  rise in the requests to be handled by the server. Thus, eventually a server reaches a bottleneck leading to slow performance of the server. There are several ways of handling such spike in the traffic. One of the ways is to increase the number of servers. However, even with the increased set of servers, there are still chances of one of the servers being overloaded. This is where Load balancers come to the rescue.

Understanding the load balancer

A load balancer, as the name suggests, is an intermediate layer to balance the load being sent to the web server. The image below provides a high level idea of the positioning of a load balancer in a hosting environment.

Load Balancer
Load Balancer Concept

As discussed in the above section, the primary step to handle a huge traffic is to increase the number of servers. This step involves increasing the servers in different regions as needed. By performing this step, we are able to direct the traffic to specific locations instead of having the traffic bombard a single server. However, this concept works only when the crowd is distributed across these regions. This scenario is better explained using an analogy below.

Imagine an aircraft with equal number of business class and economy class seats. The passengers who book an economy class seat are normally more than the ones trying to book a business class ticket. This leads to the rise in traffic to book an economy class ticket and consequently the probability of getting an economy seat reduces. In a similar manner, when the visitors from a specific region rise, the capability of the server to handle more visitors takes a toll. However, at the same time, the other server continues to run normally. This is where load balancer comes to rescue.

Load balancer runs an algorithm in the backend to monitor and identify the load handling capacity and current load on the servers. A load balancer is the first layer that a web request would hit when it tries to find your website. A load balancer does the job of efficiently distributing the web traffic to the server that can respond to the request in an optimum time. Thus, it manages the forwarding of request to a server pool(a collection of servers). In addition to forwarding the requests, the modern load balancers can also filter traffic to avoid spamming or attacks such as DDoS.

Implementing Load Balancers

Setting up a set of independent servers in every desired region is quite simple. All you need to do is replicate the setup and get the application to run on the setup. However, setting up load balancer is a tricky job. As discussed, load balancers typically route the traffic to different servers. This traffic could be from various protocols and load balancer handles it all. Several developers also use load balancer as a port re-routing layer to direct the user request to the correct port.

The most famous load balancer tool or software being used in the industry today is NGINX. It is not just a load balancer but a platform that powers web servers, load balancers, microservices as well as API gateways. The basic NGINX variant is an open source tool and easily available for install in MacOS, Linux and Windows as well. Further, we will cover the configuration of NGINX as a load balancer. It is being assumed that you would already have NGINX installed in your server system. In case you don’t have it installed, you can refer this link for Linux installation.

Configuring the load balancer in NGINX

Let us consider 4 servers established in different regions. The IP address of these servers are as listed below:


To configure the load balancer, you need to create a file load-balancer.conf in the conf.d folder of NGINX. To do this, execute the below command in Ubuntu.

Note: We would be covering the configurations for Ubuntu only in this article to limit the length. However, the configurations remain the same even for MacOSx and Windows. It is just the file path that change.

In the file, enter the below code to configure the backend servers that NGINX should route traffic to.

With this simple piece of code, NGINX routes the traffic in a balanced manner to these three server. As a next step, we need to remove the symbolic link of default sites that are enabled in the NGINX during installation. Execute the below command to do so.

As soon as it is restarted, the load balancer starting acting its part. The load balancer works in a round robin fashion by default.

Problems with Round Robin Load Balancer

Round Robin load balancing has its own drawbacks. Although it has minimal configuration to begin with, the drawback is a major one. For the servers where session management is important, sending requests in a round robin fashion, it becomes difficult to handle sessions. To resolve this problem, we can use the IP hashing algorithm to bind the request from a specific IP to a specific server. To configure the IP hashing, modify the above file as shown below.

Restart the NGINX after saving this. Now, your application is ready to balance the load along with sessions being managed in an intact manner.

Benefits of using NGINX

NGINX is the simplest load balancer being used widely across the software industry. Some of its features include:

  • Light-weight backend
  • No limit to number of servers
  • Can be used to route traffic based on ports
  • Can be used to filter traffic
  • Prevents DDoS

Although NGINX is simple and easy to setup, most of the hosting platforms provide easy to use GUI to setup load balancers. Some such hosting providers are listed below.


It is extremely important to setup a load balancer when you are planning to setup multiple server to handle heavy traffic. It ensures that each server resources is utilised efficiently. For a managed session server, it is important to make sure that IP hashing is used to handle the sessions connected with the server.

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Looking for a chatbot?

Latest Posts

Share via
Copy link
Powered by Social Snap