Whenever we want to connect to the Internet, we need the websites to be accessible as quickly as possible to have the best user experience. However, we must remember that these websites are hosted on web servers, and these, in turn, have a capacity limit. A high-demand website couldn’t survive without a load balancer. This tool allows the website that we manage to be always available and to be able to serve all requests at the maximum possible speed. This tutorial will explain how a load balancer, also known as Load Balancer, can improve the performance of your website.
Websites that offer services such as online shopping, online press, or multimedia services have a high traffic demand almost continuously, especially in the evening, when there is more Internet traffic because all people are in their houses resting from a hard day’s work. The web servers are mainly responsible because the page load is high-speed when we visit a particular website to provide the best possible user experience.
Each online business ( e-commerce ) must bear in mind that it is mandatory to have high-performance and high-availability web servers. Just a few brief events of slowness or no access to shopping sites, and even problems when making payments, can influence the customer’s decision to make their purchases again on such sites.
How can a load balancer help?
Suppose you are responsible for the infrastructure that gives life to high-demand websites such as e-commerce, and you want to ensure that web servers maintain high levels of service. In that case, you must consider setting up an infrastructure with load balancing or also known as Load Balancing.
What are they for? These ensure that web traffic is not concentrated on a single server, which eventually saturates due to the thousands of requests per second from different clients. In turn, this saturation leads to extreme slowness of the websites or simply that it is not available and it returns an error. A web server itself can fulfill the “role” of Load Balancer. Instead of constantly investing in acquiring a single server with increasing capacity, one could opt for two or more servers with identical performance to balance the traffic in each of them.
To apply this balancing process, it is customary to opt for the Round-Robin DNS functionality to distribute client requests to web servers evenly. The result is consistent server performance and availability. The disadvantage of this process is that it is not applicable in a scenario where the servers have different features and capacities. Round-Robin treats all available servers reasonably and does not verify whether they are operating or not available.
As a result of this, the different providers applied improvements. They did this by creating tools that ensure servers are fault-tolerant: load balancers. This, by redirecting traffic and clients from a failed server to another available one. Thus, users will perceive very few inconveniences and zero failures. These tools can be used both in multiple website environments as well as those with only one.
Operating scheme
As we have mentioned, a load balancer is a tool that directs a client to the webserver with the highest availability among those with the same content. This process is entirely transparent for whoever accesses a particular site, so we cannot detect this with the naked eye. We can use this scheme to understand better how it works:
Two web servers are responsible for feeding a single website. The IP addresses are:
192.168.0.4 for server web1.example.com
192.168.0.5 for server web2.example.com
A load balancer is implemented with the virtual hostname www.example.com and its virtual IP 192.168.0.10. With name and virtual IPs, this virtual host will serve the DNS server to resolve access to the “example” website.
A person wants to access www.example.com, so what happens is that they are requesting to access the load balancer of the servers that initially host the website.
That load balancer now checks which web server is available for the user’s request. Once that is done, the chosen server receives the request.
Once it has been processed, the server responds to the request by providing access to www.example.com. This could change according to how it has been implemented.
Types of load balancers
They are classified into three types:
Hardware type consists of a dedicated server with a specific operating system and software to carry out the load balancer process. This server integrates the web servers using Plug and Play solutions, which means that as soon as they are connected, they work with little or no pre-adjustments.
Switch type: A load balancer of this type requires a Layer 2 or Layer 3 switch to integrate the balancing process. No intermediary device is needed between the control and the webserver.
Software-based: In this case, you do not need to modify any network connectivity features. You can install the software for the purpose on the web servers themselves. However, you can opt for a dedicated server to fulfill the role of the load balancer.
In any case, the fundamental purpose is to monitor the capacity of the web servers, select the appropriate server for each client’s requests, and redirect traffic between the client and the server.
How to redirect traffic
As we already know, one of the primary purposes of a load balancer is to redirect client traffic to the appropriate server. Next, we will share how they do it:
MAT
This abbreviation stands for Media Access Control Address Translation. This method requires each webserver to use the load balancer’s IP address as a loopback interface address, in addition to its IP. When the load balancer receives the request from the client, it begins to select the appropriate web server. Then it changes the destination MAC address in the data packet to make up the client’s request to the chosen web server. Then that request travels to the server, which contains the client’s IP address as data. In this way, it guarantees a direct response to it.
One point to consider is that whenever the “chosen” web server responds to the client’s request, it masks its original IP with the one corresponding to its load balancer. As if the client requested it initially.
NAT
The method consists of changing the destination IP address of the client’s request. Initially, the latter targets the load balancer’s IP. However, the famous “nateo” process changes this IP and assigns the corresponding one to the “chosen” server. This process is performed by the load balancer itself using its given IP address. Also, in the middle of this process, the source IP address is the load balancer rather than the client’s IP address. After the load balancer redirects the response to the client, it changes the destination IP address to the one corresponding to the client. Consequently, the source IP address is that of the load balancer.
What is achieved is to hide the original IP of the web server so that it is not visible to clients. So web servers can use any IP, even if it is private. These servers do not need to connect directly to the load balancer belonging to the same local network segment. As long as web servers and load balancers can communicate using static routes or network routing protocols, it is unnecessary.
TCP gateway
In this method, the load balancers have to redirect the traffic at the TCP layer and higher: this and the client making the connection request establish a TCP connection. So the load balancer receives the requested data before searching for the most appropriate server. The load balancer then establishes a TCP connection with the designated server to transmit the client’s request. Such a load balancer also passes the response from the server to the client through the TCP connection. Thus, we see that the TCP protocol acts as an intermediate between the potential destination servers, the load balancer, and the client.
As we can see, the role of a load balancer has become increasingly essential. Mainly because websites are having more and more customer requests, that is, more users who want to access the different pages. Not only e-commerce is one of the sectors that should adopt this type of tool and any other with high user traffic every day.