RousselTMLEARNING

Proxy & networking

Load balancing: principles, algorithms and use cases

Discover how load balancing works, its role in high availability, and the details of algorithms such as round robin and least connections.

1. What is load balancing? #

Definition and fundamental role in web architectures.

The load balancer #

Load balancing is a mechanism that distributes network or application traffic across a set of servers (the backend pool). Its purpose is to optimize resource usage, maximize throughput, reduce response time and, above all, avoid overloading a single server.

Why is it essential? #

Without load balancing, your infrastructure has a SPOF (single point of failure). If your only server goes down, the service stops. Load balancing enables high availability (redundancy) and horizontal scalability (adding servers to absorb traffic growth).

2. Load balancing algorithms #

How does the load balancer choose the destination server?

Round robin #

This is the simplest algorithm: requests are sent to the servers sequentially. It is ideal when the servers have identical capacities.

Info: It is the default algorithm up to HAProxy version 3.2.
  • Pros: extremely simple, no overhead, perfectly fair on identical servers.
  • Cons: inefficient if servers have different capacities or if some requests are heavier than others.

HAProxy configuration example:

backend app_servers
    balance roundrobin
    server s1 192.168.1.10:80 check
    server s2 192.168.1.11:80 check
Round robin diagram

Weighted round robin #

Each server has a weight proportional to its processing capacity. A more powerful server handles a larger share of requests.

  • Pros: suited to heterogeneous server fleets, predictable behavior.
  • Cons: requires manual weight configuration and does not adapt to the real instantaneous load.

HAProxy configuration example:

backend app_servers
    balance roundrobin
    server s1 192.168.1.10:80 check weight 100
    server s2 192.168.1.11:80 check weight 200
Weighted round robin diagram

Least connections #

This algorithm sends the new request to the server with the fewest active connections. Very effective for sessions of variable duration.

  • Pros: effective dynamic balancing, ideal for persistent connections (databases, WebSockets).
  • Cons: slight overhead to track connections; can be misleading if requests vary in complexity.

HAProxy configuration example:

backend app_servers
    balance leastconn
    server s1 192.168.1.10:80 check
    server s2 192.168.1.11:80 check
Least connections diagram

Weighted least connections #

Combines the least connections algorithm with a weight system to favor the most robust servers with little active load.

  • Pros: the most accurate for mixed infrastructures with long sessions.
  • Cons: uses more computing resources on the load balancer (overhead).

HAProxy configuration example:

backend app_servers
    balance wlc
    server s1 192.168.1.10:80 check weight 100
    server s2 192.168.1.11:80 check weight 200
Weighted least connections diagram

Least response time #

Sends requests to the server with the shortest response time and the fewest active connections. Ideal for maximum responsiveness.

  • Pros: directly optimizes the user experience, avoids slowed-down servers.
  • Cons: compute-intensive; risk of instability if response times change abruptly.

HAProxy configuration example:

backend app_servers
    balance rtime # Requiert HAProxy 2.x+
    server s1 192.168.1.10:80 check
    server s2 192.168.1.11:80 check
Least response time diagram

IP hash / source hash #

The user's IP address determines the destination server, guaranteeing session persistence (stickiness).

  • Pros: persistence without server-side cookie management.
  • Cons: possible imbalance if many users share the same IP (proxy/NAT); full redistribution if the number of servers changes.

HAProxy configuration example:

backend app_servers
    balance source
    server s1 192.168.1.10:80 check
    server s2 192.168.1.11:80 check
IP hash diagram

Random #

The load balancer picks a server at random from the pool. Simple and statistically effective on massive traffic volumes.

Info: It has been the default algorithm since HAProxy version 3.3.
  • Pros: zero overhead, very efficient for very large clusters.
  • Cons: no guarantee of fairness on small request volumes.

HAProxy configuration example:

backend app_servers
    balance random
    server s1 192.168.1.10:80 check
    server s2 192.168.1.11:80 check
Random diagram

3. Tools and application examples #

Common software and cloud solutions.

Specialized software #

Cloud and hardware #

  • Cloud load balancers: AWS ELB, Azure Load Balancer or Google Cloud Load Balancing are very popular managed services.
  • Hardware: physical appliances such as F5 BIG-IP, although less common today in favor of software and cloud.

Conclusion #

A critical element for resilience.

The move towards the service mesh #

Load balancing is no longer limited to the network edge. In microservice architectures (Kubernetes), service meshes (such as Istio or Linkerd) are used to balance load directly between the application's internal components.

Related articles

Anatomy of HAProxy configuration, clustering and high availability

Understand the structure of an haproxy.cfg file: the global, defaults, frontend (high performance), backend a…

HAProxy in Kubernetes: the high-performance Ingress Controller

Discover in depth how HAProxy integrates with Kubernetes: direct-to-pod architecture, hot update options (DNS…

What's new in HAProxy: OpenTelemetry, native JWT and performance optimizations

Explore HAProxy's latest innovations: native OpenTelemetry support for observability, JWT validation at the e…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!