Without a load balancer, the service address points to a single server, which becomes both a bottleneck as load grows and a single point of failure. A load balancer accepts requests on one virtual address and spreads them across a pool of servers, skipping any that don’t respond. This is how services scale horizontally and survive the loss of individual machines without downtime.
L4 and L7
Load balancers work at different network layers, which determines their capabilities and cost. The L4/L7 terms come from the OSI model: L4 sees only connections, while L7 sees application requests.
| Aspect | L4 (transport) | L7 (application) |
|---|---|---|
| What it sees | IP addresses and ports, TCP and UDP streams | whole HTTP requests: paths, headers, cookies |
| Decision | where to send a new connection | where to send each request |
| Overhead | minimal: the decision is just choosing an address | higher: the request has to be parsed and understood |
| Typical uses | TCP services, DNS, games, streaming | websites and APIs, path-based routing |
Distribution algorithms
- Round robin: requests go in turn, ignoring load; the weighted variant sends more requests to more powerful servers.
- Least connections: a new request goes to the server with the fewest active connections; suits long sessions (LDAP, SQL) and works less well for short HTTP requests.
- IP hash: connections from one client always reach the same server (stickiness).
- Random: a random choice; useful on large farms where servers are added and removed often.
Health checks
The balancer periodically polls servers with health checks and stops sending traffic to any that fail to respond or return an error. It checks a TCP port or a specific URL, for example GET /healthz; the interval, timeout and number of failures are configurable. Autoscaling relies on the same checks: a server that fails them is replaced with a new one.
Sources
the term is written from these pages- AWS Elastic Load Balancing — What is an Application Load Balancer?docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html(opens in a new tab)
- nginx — Использование nginx как HTTP-балансировщика нагрузкиnginx.org/en/docs/http/load_balancing.html(opens in a new tab)
- HAProxy Configuration Manual (3.2) — balancedocs.haproxy.org/3.2/configuration.html(opens in a new tab)
Verified 9 Nov