Skip to main content
How does a load balancer work? Imagine your online store runs on a single server that can handle 1,000 requests per second. During a sale you suddenly get 2,000 requests per second — one server is no longer sufficient. The typical solution is to scale horizontally: add more identical servers to run the same application. For example, if we run our application on four servers — A, B, C, and D — together they can handle 4,000 requests per second and provide redundancy if a server fails. But users only know a single address for your site and cannot choose a server directly. This is where a load balancer comes in. A load balancer sits in front of your application servers. Every client request arrives at the load balancer first; the load balancer then forwards the request to one of the backend servers. Common implementations include NGINX, HAProxy, or managed cloud load-balancing services.
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.
How does the load balancer pick a server?
  • 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.
Load balancing policies at a glance: 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.
With D marked unhealthy, traffic is routed only to A, B, and C. In our example those three servers can handle up to 3,000 requests per second, which is still above the 2,000 requests per second being received. What if the load balancer itself fails? A single load balancer can be a single point of failure. To avoid downtime, deploy load balancers in a high-availability configuration. A common pattern is active-passive failover: run two load balancers that share a single virtual IP (VIP). The active instance owns the VIP and serves traffic; the standby monitors the active instance and takes over the VIP if the active fails. This behavior is commonly implemented with VRRP, keepalived, or cloud provider HA features.
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.
Putting it all together — request flow and best practices
  • 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.
A simple rule to remember: the load balancer first determines which backends are healthy, then decides which healthy server should receive the next request. Further reading and references

Watch Video