Load balancing assigns each new connection or request to one eligible backend in a replica pool. It gives clients one stable endpoint while the service gains horizontal scale and can remove failed replicas from rotation.

It does not create capacity or availability by itself. An overloaded pool remains overloaded, a bad readiness signal can empty the pool, and a single load-balancer instance simply moves the point of failure. The design must cover backend eligibility, routing policy, overload behavior, and failure of the balancing tier.

Routing Decision

Routing happens in two steps. Health policy first removes destinations that should not receive new work. The balancing algorithm then selects from the remaining pool.

LayerVisible inputUseful whenBoundary
L4 transportSource and destination address, port, protocol, connection stateGeneric TCP or UDP distribution and connection-level routingCannot choose by HTTP host, path, header, or cookie
L7 applicationParsed HTTP request dataContent routing, canaries, edge authentication, or HTTP policyAdds protocol processing and makes the balancer part of the application request path
flowchart LR
    C[Client] --> LB[Load Balancer]
    LB --> A[Server A]
    LB --> B[Server B]
    LB --> D[Server C]

L4 is the smaller contract when transport metadata is enough. L7 becomes necessary as soon as the decision depends on HTTP content. A system may use both, for example an L4 edge in front of regional L7 proxies.

Algorithms

The algorithm encodes an assumption about work. A good choice makes that assumption explicit and tests it against the real request distribution.

Algorithm | How it routes | Prefer when | Main risk --- | --- | --- | --- Round robin | Cycles evenly through the pool. | Instances and request costs are similar. | A slow instance still receives an equal share. Weighted round robin | Cycles according to configured capacity weights. | Instance sizes differ in a stable, measurable way. | Static weights become stale under throttling or noisy neighbors. Least connections | Selects the backend with the fewest active connections. | One active connection roughly represents one active request, as with non-multiplexed long-lived streams. | HTTP/2 or gRPC multiplexing and idle keep-alive pools break that proxy. IP hash | Maps a client address to a backend. | Coarse affinity is required and client addresses are well distributed. | NAT can collapse many clients onto one address and create a hotspot. Consistent hashing | Maps an application key onto a ring. | Cache locality or shard affinity must survive membership changes. | Uneven tokens and hot keys still skew traffic. Least latency or least response time | Uses recent response measurements, often with in-flight work. | Backend performance varies and measurements remain fresh. | Delayed signals can make traffic chase a temporary winner. Session affinity | Constrains future requests to a prior backend. | Local session state must survive during a legacy migration. | Failover weakens and existing hotspots persist.

software architecture load balancing

The visual is an orientation map. Sticky round robin is affinity layered over a base algorithm. IP or URL hashing is not a consistent-hash ring. Health eligibility still comes first. No selection policy can compensate for a pool containing backends that cannot serve.

AI inference exposes the weakness of simple proxies for work. Token count, batching, model choice, and cache hits change request cost. Least connections can be a better starting point than round robin only when connections approximate active requests. For multiplexed HTTP/2 or gRPC traffic, prefer least outstanding requests or streams, or scheduler-visible model concurrency. Representative p95 and p99 latency together with backend saturation still decide whether that signal works.

Health and Overload

Load balancing consumes readiness as a routing signal. Software Architecture/Distributed Systems/Health Checks separates readiness from restart-oriented liveness and from passive failure evidence. The important boundary is whether sending the request elsewhere can improve the result.

Removing every replica because one shared database is unavailable replaces controlled application failures with an empty pool. Failure and recovery thresholds add hysteresis, while slow start limits traffic to a cold backend after it re-enters rotation.

Balancing also stops helping once all eligible backends are saturated. That path needs bounded queues, admission control, or load shedding. Sending the same excess work to a different replica only moves the queue.

Deployment Controls

Cloud product names hide several independent decisions:

ControlOptionsConsequence
Protocol layerL4 TCP/UDP or L7 HTTPL7 enables content routing and HTTP policy. L4 supports generic transport with less parsing
ReachabilityInternal or internet-facingChanges addressing, firewall exposure, and trust boundary
ScopeZonal, regional, or globalWider scope can improve failover and proximity but adds control-plane and cross-region complexity
Data pathProxy or pass-through/direct server returnProxy centralizes TLS and observability. Pass-through preserves source/data-path properties but exposes more backend responsibility
TLS boundaryTerminate, re-encrypt, or pass throughDetermines certificate ownership, inspection, and end-to-end encryption
AffinityNone, cookie, source hash, or application keyImproves locality but couples sessions to backend availability
Zone policyLocal-zone preference or cross-zone balancingTrades fault isolation and egress cost against access to spare capacity

These controls should be selected before a provider SKU. Azure Load Balancer is an L4 family with regional public and internal variants plus a cross-region tier. Application Gateway is regional L7, while Front Door is a global HTTP edge. AWS and Google Cloud divide the same capabilities differently. Similar names do not guarantee the same source-IP, health, cross-zone, or failover behavior.

The balancing tier needs its own availability story. Managed services usually replicate the data plane, while self-hosted proxies need multiple instances and a separate mechanism for directing clients to them. Health probes, TLS termination, cross-zone routing, and affinity remain separate controls even when one product exposes all of them.

How Load Distribution Breaks

FailureMechanismRepair
Sticky sessions concentrate loadAffinity keeps clients on old assignments after traffic or capacity changesExternalize session state. Keep affinity narrow and short-lived during migration
A shared outage empties the poolReadiness checks treat a fleet-wide dependency failure as an instance defectInclude a dependency only when another backend can serve more successfully
A recovered backend fails againFull traffic arrives before caches, connections, or model clients are warmRequire sustained recovery and ramp traffic up gradually
TLS creates an accidental plaintext hopTermination location and trust boundary were left implicitDocument certificate custody and choose termination, re-encryption, or passthrough deliberately
Graceful shutdown still drops workThe backend is killed before it drains existing connectionsRemove it from eligibility, wait for propagation, drain, then terminate

References