Load Balancing refers to efficiently distributing incoming network traffic across a bunch of back end servers; it is also commonly known as a server farm or server pool.
Most of modern high traffic websites have to serve thousands or even millions of concurrent requests from users or clients then return the correct text, video, images, or application data in a very fast and consistent and reliable manner. In order to cost effectively scale to get these high volumes, this usually means adding more servers.
A load balancer serves as the ‘traffic cop’ sitting in front of your servers before routing client requests aboard all servers suited of executing these requests in a manner which maximizes the speed and capacity utilization as well as making sure that no server is overworked to the point where it degrades performance. Once a single server goes down, the load balancer redirects traffic to the servers that are still currently online. Once a new server is added to the server group, then the load balancer immediately begins sending requests to it.
In this manner, a load balancer is capable of executing the following functions:
- Distributing client requests or network load efficiently across numerous servers.
- Assuring high availability and reliability by sending requests specifically to servers that are online.
- Grants flexibility to add or detract servers as demand dictates.
Load Balancing Algorithms
Differing load balancing algorithms grant differing benefits, the choice of load balancing method should be dependent on what you need.
- Round Robin – Requests are given across the group of servers constantly.
- Least Connections – A new request is sent to the server with the least current connections to clients. The relative computing capacity of every server is divided into determining what one has the least connections.
- IP Hash – The IP address of the client is used to determine what server gets the request.
Usually the information of a user’s session is stored locally in the browser. For example, in a shopping cart application, the items in a user’s cart may be stored at the browser level until the user is prepared to purchase them. Switching which server receives requests from that client in the middle of the shopping session could create performance issues or even a complete transaction failure. Whenever a case like that happens, it is important that all requests from a client are sent to the same server for the time of the session. This is known as session persistence.
The best load balancers should be able to handle session persistence as required. A different use case for session persistence is when an upstream server stores information requested by a user in its cache to improve performance. Changing servers could cause that information to be retrieved for the second time causing performance inefficiencies.
Hardware vs. Software Load Balancing
Load balancers usually come in two flavors: hardware-based and software-based.
Sellers of hardware-based solutions load proprietary software onto the machine they provide which tends to use specialized processors. To endure increasing traffic on your website, you may need to purchase more or bigger machines from the seller.
Software solutions usually run on commodity hardware causing them to be less expensive and more flexible. You could install the software on the hardware of your choice or in cloud environments like AWS EC2.