Load Balancing
Load balancing refers to the efficient distribution of incoming network traffic across a group of backend servers, also known as a server farm or server pool.
Modern high-traffic websites must handle hundreds of thousands, if not millions, of concurrent requests from users or clients and deliver the appropriate text, images, video, or application data quickly and reliably. To cost-effectively scale to meet these high volumes, current best practices in computing typically involve adding more servers.
A load balancer acts as a “traffic cop” in front of your servers, routing client requests across all servers capable of fulfilling them. This approach maximizes speed and capacity utilization while ensuring that no single server is overworked, which could degrade performance. If a server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the server group, the load balancer automatically begins directing requests to it.
Load Balancing Algorithms
- Round Robin: Requests are distributed across the group of servers sequentially.
- Least Connections: A new request is sent to the server with the fewest current connections to clients. The relative computing capacity of each server is factored into determining which one has the least connections.
- Least Time: Sends requests to the server selected by a formula that combines the fastest response time and fewest active connections. Exclusive to NGINX Plus.
- Hash: Distributes requests based on a key you define, such as the client IP address or request URL. NGINX Plus can optionally use consistent hashing to minimize load redistribution if the set of upstream servers changes.
- IP Hash: The client’s IP address is used to determine which server will receive the request.
- Random with Two Choices: Selects two servers at random and sends the request to the one with the fewest connections, based on the Least Connections algorithm. For NGINX Plus, the Least Time algorithm can be used instead, if configured.
X-Forwarded Headers
When using a load balancer, clients do not connect directly to the application servers; instead, the load balancer sits in between. As a result, application servers lose metadata about the original client and connection details. The use of X-Forwarded HTTP headers allows this information to be passed along and accessed by the application servers. This is essential for some applications and beneficial for others. The following X-Forwarded headers are recommended for all Oracle Restaurants web applications:
- X-Forwarded-For
- X-Forwarded-Scheme <<Scheme/Proto?>>
- X-Forwarded-Proto <<Scheme/Proto?>>
- X-Forwarded-Host
Parent topic: Network Infrastructure