What is load balancing?
Load balancing is a technique used to distribute the workload across multiple computing resources and servers. The aim of load balancing is to optimize resource usage and to avoid a single resource or server getting overloaded. If a website or application receives a lot of requests/traffic, load balancing is required to ensure stable performance and uptime for the users.
To perform load balancing it is necessary to have a server pool or server farm, which are all connected to a load balancer. The load balancer acts as the middleman between incoming requests from website users and the servers. When a new request comes in the load balancer distributes it to the server that is best fit to handle it based on the load balancing algorithm (method) being used.
A load balancer typically supports either Layer 4 (L4) or Layer 7 (L7). Layer 4 distributes traffic based on transport data, e.g. IP address and TCP port. Meanwhile Layer 7 distributes traffic based on application layer data and attributes, e.g. HTTP header, uniform resource identifier and HTML form data.
The data flow/communication between each item in the Umbraco environment with a load balancer
A load balancer can either be hardware-based or software-based. Commonly proprietary software has been installed on dedicated hardware, but with the growing popularity of cloud environments it is more and more common to see software running on virtual machines instead. For more advanced requirements an application delivery controller (ADC) is used to not only take care of load balancing, but to also improve security and resiliency.
Load Balancing Algorithms (Methods)
Load balancers can use a variety of different algorithms or methods to decide where to redirect a user request. These algorithms are based on different criteria and which to use often depends on the needs and complexity of the application used. Here is a list of the main load balancing algorithms used by ADCs.
1. The round robin method
When using the round robin method, the load balancing is done by continuously cycling through the servers that are available. When a new request comes in it is assigned to the server at the top of the list and that server is moved to the bottom of the list for the following request.
2. The least connection method
This method is often the default, where the server with the fewest active connections is picked for new incoming requests.
3. The least response time method
This method is an expansion to the above method. When using the least response time method the load balancer checks for fewest active connections as well as the lowest average response time.
4. The least bandwidth method
As the name suggests this method picks the server with the least bandwidth used currently. This is measured in megabits per second (Mbps).
5. The least packets method
The least packets method looks at a certain period of time and the amount of packets each server has received. The one with the least packets received will get the request. The period of time used in this method can be configured.
6. The chained failover method
This method uses a predetermined order of all servers in the pool, which are configured in a chain. When a new request comes in it is sent to the first server in the chain. If that server is unable to accept the request the next server in the chain is sent all new requests. This server keeps getting sent requests until it is unable to handle it. When that happens the next server in the chain takes over.
7. The adaptive methods (multiple)
Adaptive methods are used in conjunction with other methods. By using adaptive methods, various real-time information about the different servers in the pool is used to decide which is the best fit to handle the request.
8. The IP hash method
The IP hash method uses the IP of the user and the server and combines them to create a unique hash key. This ensures that a user is sent to the same server in future sessions. This is especially helpful if actions between sessions has to be kept alive (e.g. products put in the shopping cart).
9. The weighted methods (multiple)
Most of the load balancing methods can be configured to be weighted. When working with weighted methods each server in the pool will get a numerical value, that works as a ranking in case of two servers being otherwise equal.
How to do load balancing with Umbraco CMS
Load balancing environments is supported when using Umbraco CMS. To help you get started we recommend that you take a look at our documentation on load balancing. If you do not currently have a load balancing setup, but want to learn more about best practices when setting it up using Azure Cloud, we have a 1 day training course on Umbraco Load Balancing.