Basic balancing techniques

The three scheduling algorithms which NGINX supports are round-robin, least connections, and hashing.

Load balancers configured in a round-robin fashion distribute requests across the servers in a sequential basis; the first request goes to the first server, the second request to the second server, and so on. This repeats until each server in the pool has processed a request and the next will simply be at the top again. The following diagram explains the round robin scheduling algorithm:

This is the most simplistic method to implement, and it has both positive and negative sides. The positive is that no configuration is required on the server side. The negative is that there's no ability to check the load of the servers to even out the requests.

When configured to use the least connection method of load balancing, NGINX distributes the requests to the servers with the least amount of active connections. This provides a very rudimentary level of load-based distribution; however, it's based on connections rather than actual server load.

This may not always be the most effective method, especially if one particular server has the least amount of connections due to a high resource load or an internal issue.

The third method supported by NGINX is the hash method. This uses a key to determine how to map the request with one of the upstream servers. Generally, this is set to the client's IP address, which allows you to map the requests to the same upstream server each time.

If your application doesn't use any form of centralized session tracking, then this is one way to make load balancing more compatible.