Load Balancer

Networking

Overview

A load balancer distributes incoming requests across multiple servers so no single server is overwhelmed, improving the system's availability and scalability.

If one server dies, it reroutes traffic to healthy servers, enabling uninterrupted service.

Details

They're categorized by the layer they operate at. An L4 load balancer distributes fast at the TCP/UDP level, looking only at IP and port; an L7 load balancer inspects application data like HTTP headers, path, and cookies to route more intelligently (e.g. `/api` to API servers, `/img` to image servers). L7 overlaps heavily with reverse-proxy functionality.

Distribution algorithms include round-robin, least connections, weighted, and IP hash. 'Sticky sessions' keep sending a user to the same server to preserve in-memory session state, but they hinder scaling and failover, so a stateless design that moves sessions to external storage (like Redis) is preferred. Health checks automatically remove dead servers, and the load-balancer tier itself is made redundant via clustering or DNS round-robin/anycast to avoid it becoming a single point of failure.

Related types