How Load Balancers Work: Round Robin, Least Connections and More

How Load Balancers Work: Round Robin, Least Connections and More

Load balancers are a fundamental building block of scalable web infrastructure. By distributing traffic across multiple servers, they prevent any single machine from becoming a bottleneck and provide high availability if a server fails. Understanding load balancing algorithms helps you choose the right strategy for your workload.

Layer 4 vs Layer 7 Load Balancing

Layer 4 load balancers operate at the transport level, routing based on IP address and TCP/UDP port. They’re extremely fast but can’t inspect request content. Layer 7 load balancers operate at the application level, routing based on HTTP headers, URLs, cookies, or content type. They’re more flexible but have slightly more overhead. Most modern load balancers operate at Layer 7.

Round Robin

The simplest algorithm distributes requests sequentially across servers: server 1, server 2, server 3, server 1 again, and so on. It works well when all servers have equal capacity and requests take roughly the same time. It doesn’t account for server load, so a server processing a long-running request will still receive new requests at the same rate.

Weighted Round Robin

An extension of round robin that assigns more requests to servers with greater capacity. A server with twice the CPU and RAM might have a weight of 2, receiving twice as many requests as a server with weight 1. Useful when backend servers have different hardware specifications.

Least Connections

Routes each new request to the server with the fewest active connections. More adaptive than round robin for workloads with variable request durations. If one server is handling many slow long-polling connections, new short requests are directed elsewhere.

IP Hash (Sticky Sessions)

Hashes the client’s IP address to always route requests from the same client to the same server. This maintains session affinity, which is required if your application stores session state locally on the server. The downside is uneven distribution if many clients share a NAT IP address.

Health Checks

Load balancers continuously probe backend servers with health checks (HTTP GET to a /health endpoint, TCP connection checks). Servers that fail health checks are automatically removed from rotation and re-added when they recover. This is what makes load balancers a key component of high availability architectures.

Monitor your endpoints. Use the HTTP Tester on devutilitypro.com to simulate requests to your load-balanced endpoints and verify that health checks and routing rules are working correctly.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top