Load balancing is a form of efficiently distributing incoming network traffic across multiple backend servers, also known as a server farm.
Today’s websites serve hundreds of thousands, if not millions, of simultaneous requests from users or clients and must quickly return the right text, images, video, or application data. To scale to meet these high volumes in a cost effective manner, modern computing best practice tends to require the addition of more servers.
A load balancer is the “traffic cop” sitting in front of your servers and routing client requests across your server farm in a way that maximizes speed and capacity utilization and ensures that no single server is overworked, which could lessen performance. If one server goes down, the load balancer redirects traffic to the other servers online. When a new server is added, the load balancer automatically begins to send it requests; providing the flexibility to add or subtract servers as needed.
Different load balancing algorithms offer different benefits. The type of load balancing method depends on your needs:
- IP Hash – The client’s IP address is used to determine which server receives which request;
- Round Robin – Requests are distributed sequentially across the group of servers;
- Least Connections – A new request is sent to the server with the least current connections to clients i.e. the computing capacity of each server relative to the others is part of determining which one has the least connections.
The best load balancers can also handle session persistence as needed, which involves storing information about a user’s session locally in the browser in order to optimize their experience.
Many rapidly changing applications need new servers to be added or taken down on a frequent basis. In environments such as the Amazon Elastic Compute Cloud (EC2), users only pay for the computing capacity they use while simultaneously ensuring that capacity scales up in response to traffic spikes. In this kind of environment, it helps if the load balancer can dynamically add or remove servers from the group without interrupting existing connections.
Load balancers are typically either hardware-based or software-based. Vendors of hardware-based solutions load proprietary software onto the device they provide, which usually uses specialized processors. To handle increasing traffic to your website, you then have to purchase more or larger machines from the vendor. Software solutions, meanwhile, tend to run on commodity hardware, making them more flexible and a cheaper option. You can install the software on your choice of hardware, or in cloud environments such as AWS EC2.