Search
4 results for “system-design”
Search results
Load Balancers
How load balancers distribute traffic across servers, algorithms, health checks, Layer 4 vs Layer 7, and the failure modes that show up at scale.
What is the difference between Layer 4 and Layer 7 load balancing?
A Layer 4 load balancer operates at the transport layer, routing based on IP address and port without inspecting the actual request content; it is fast and protocol-agnostic but cannot route based on things like URL path or headers. A Layer 7 load balancer operates at the application layer, so it can inspect HTTP requests and route based on path, host header, cookies, or content type, more flexible (path-based routing, A/B testing, session affinity by cookie) but with more per-request processing overhead.
How does a load balancer detect and handle an unhealthy backend server?
Via health checks, periodic requests (a lightweight HTTP endpoint like /healthz, or a TCP connection check) sent to each backend on an interval. A server that fails a configurable number of consecutive checks is marked unhealthy and removed from the rotation; it is added back only after passing a configurable number of consecutive successful checks, which avoids flapping a server in and out of rotation on a single transient failure.
Why is round robin sometimes a bad load-balancing algorithm choice?
Round robin assumes every server and every request is roughly equal cost, which is not always true, if backend servers have different capacities, or requests vary wildly in cost (a cheap health check vs. an expensive report generation), round robin can overload a server that happens to be mid-way through several expensive requests. Least-connections or weighted algorithms account for current load or server capacity instead of blindly cycling through the list.