Load balancers are available as software (NGINX, HAProxy), appliance, or managed cloud services (AWS ELB/ALB, Google Cloud Load Balancing, Azure Load Balancer). Choose based on control, features, and operational overhead.
-
Round robin
- The simplest policy is round robin: request 1 → A, request 2 → B, request 3 → C, request 4 → D, request 5 → A, and so on.
- Round robin works well when requests have similar duration and resource usage because each server receives roughly the same number of requests.
-
Why round robin can fail
- If request durations vary significantly, round robin can cause imbalance. For example, if checkout requests take much longer than browsing requests and server A happens to receive many checkouts, A will have more active work while B and C may sit idle. Round robin will keep sending requests based on order, aggravating the hotspot.
-
Least connections
- To address varying request durations, many load balancers support a least-connections policy: the balancer forwards the next request to the backend with the fewest active (open) connections.
- This helps distribute ongoing work more evenly when request times are unpredictable.
What happens if a server crashes?
If the load balancer keeps sending traffic to a crashed server (for example, D), those requests will fail. To prevent this, load balancers perform periodic health checks: a small probe (TCP, HTTP, or lightweight application check) is sent to each backend at a configurable interval (for example, every 5 seconds). If a server fails to respond a configured number of consecutive times (commonly 3), the balancer marks it unhealthy and stops sending traffic to it.
- Why require multiple failures before marking a server unhealthy? A single missed check can be caused by transient network hiccups. Requiring several consecutive failures avoids prematurely removing a healthy server due to temporary issues.
Do not rely on a single load balancer instance in production. Always plan for redundancy (active-passive or active-active) and test failover so your application can tolerate load balancer outages.
- Clients send requests to a single virtual IP or DNS name.
- The active load balancer periodically probes backends to determine health.
- Among healthy backends, the load balancer selects a server using a policy such as round robin or least connections.
- If a backend is unhealthy, the balancer removes it from rotation until health checks pass again.
- If the active load balancer fails, the standby takes over the VIP so traffic continues to flow.
- NGINX: https://nginx.org/
- HAProxy: https://www.haproxy.org/
- Virtual IP (VIP): https://en.wikipedia.org/wiki/Virtual_IP_address
- VRRP (Virtual Router Redundancy Protocol): https://en.wikipedia.org/wiki/Virtual_Router_Redundancy_Protocol
- Keepalived: https://www.keepalived.org/
- Load balancing in cloud computing: https://en.wikipedia.org/wiki/Load_balancing_(computing)#Load_balancer_in_cloud_computing