Load balancer is an important component in modern IT infrastructure. Compared to the past, today's number of people that uses online services increased sharply. This rise in the popularity of the internet also causes high traffic to websites. Web servers are designed in such a way that they can serve a good amount of user requests, but when the requests become very high these servers will start getting slower and causes the website to go down. Server downtime is one of the nightmares of a company and even a small downtime of an application can adversely affect the business. So a mechanism that can prevent this situation is critical. This is where load balancers come to save us.
A load balancer is a hardware or software device that receives user requests and distributes these requests to the set of resources that is connected to its backend. This backend device can be anything like a server, storage, or any other resource that can receive requests. Typically load balancers are placed in front of a set of servers so that the user requests are shared with each of the servers by the load balancer thereby reducing the stress of individual servers.
Load balancers have a concept called backend (sometimes referred to as backend pool). This pool contains several servers or other devices that are waiting for the traffic from the load balancer. When the load balancer receives traffic, it then distributes it to one of the servers in the back-end pool.
Load balancers are intelligent devices. They can take decisions based on certain algorithms. Several load-balancing algorithms define how it should share the traffic with the back-end pool.
Dynamic load balancing Algorithms
Least connection: It checks the server with fewer connections open and then sent new traffic to it. This assumes all connections require roughly equal processing power.
Weighted least connection: It allows to set a weight to some servers assuming these servers can serve more requests than others.
Weighted response time: It sent a request to the server with the quickest request time. it found this by combining the average response time of servers.
Resource-based: Traffic is routed based on the available resource present in the server. For this, it uses an agent installed in a server that sent the resource data to the load balancer.
Static load balancing algorithms
1.Round robin: This is one of the most used algorithms. This sent traffic to the server in rotation.
2. Weighted round robin: Allows an administrator to assign different weights to each server. Servers able to handle more traffic will receive slightly more traffic than others.
3. IP hash: Combines incoming traffic's source and destination IP addresses and uses a mathematical function to convert it into a hash. Based on the hash, the connection is assigned to a specific server.
Load balancers support SSL termination. SSL is a secure socket layer, it is used to encrypt the traffic and is the standard security technology for establishing an encrypted link between a web server and a browser. When SSL termination is enabled, the load balancer decrypts the incoming encrypted traffic thereby allowing our servers to be secure. This is useful when we have multiple servers. If the load balancer is not enabled with SSL termination, then we have to enable SSL in each of the back-end servers which will incur additional costs and also it can reduce the server performance. Even though SSL termination is a good feature to have but there is some limitation like the data sent from the load balancer to the server will not be encrypted this is not a serious concern to worry about, still it's always good to have an additional measure to tackle this situation.
Nginx Load balancer with SSL termination ( Image source: Digital Ocean)
The load balancer is widely used in cloud deployments and all major providers like AWS, Azure, and GCP have load balancers that are rich in features.
Let's consider one AWS for example.
In AWS load balancers are called Elastic load balancers (ELB) and are of 4 types.
Classic load balancer: This is the oldest load balancer of AWS and doesn't have the advanced features of modern ones like host and path-based routing. It is not recommended to use this load balancer and AWS highly suggests using others.
Application load balancer (ALB): This load balancer works in the application layer of the OSI model. It is capable of host and path-based routing, which means it can read the content of the URL. It can divert traffic based on path, for instance, if the URL is ended with /image, ALB will forward the traffic to target servers that are assigned for /image path. same as in the case of /videos or others.
Network load balancers (NLB): This load balancer works in the transport layer of the OSI model(TCP/IP). It is mainly used for TCP traffic. It is the fastest load balancer and supports millions of requests per second. As it works in the Transport layer it cannot read the URL or path. it just forwards the traffic as it is to the back-end pool.
Gateway load balancer (GWLB): Gateway Load balancer helps you easily deploy, scale, and manage your third-party virtual appliances. It gives you one gateway for distributing traffic across multiple virtual appliances while scaling them up or down, based on demand. This decreases potential points of failure in your network and increases availability.
There are third-party load balancers like Nginx, HAproxy, etc that are software based. This can be installed in a server and used as a virtual load balancer. There are also docker images of them as well for quick docker deployment.
Load balancers are one of the critical devices that help to deploy a highly available and reliable web application. Load balancers are what allow all popular websites to server millions of traffic in seconds and it is one of the widely used internet devices. They can be either hardware-based or software that we can install and configure on top of a server. In both cases, the core function remains the same.
About the Author
Aswin KS is a Cloud Engineer with 4+ years of experience designing, implementing, and managing cloud infrastructure for various industries. Proven track record of designing and deploying scalable, secure, and cost-effective solutions on AWS, Azure, and Vmware. Strong understanding of cloud computing architectures, virtualization, containerization, servers, DevOps, and security.
Also Read:
How to deploy Docker in Linux and run our first web server container
What are SSL Certificates and how to create one for free