Question presented to candidate: "Explain what a load balancer actually does in front of a fleet of servers. Then walk me through the main algorithms it can use to pick a server โ round robin, least connections, hashing and so on โ and tell me when each one is the right choice and when it goes wrong."
What a strong answer should cover:
- The jobs: spread requests over a backend pool, run health checks and stop sending to failed servers, give clients one stable address, often terminate TLS, and drain connections during deploys
- Layer 4 vs Layer 7: L4 balances TCP/UDP connections by address and port; L7 understands HTTP and can route by path, header or cookie, at more CPU per request
- Static algorithms (round robin, weighted round robin, random, hash) vs dynamic ones (least connections / least outstanding requests, power of two choices), and the failure mode of each: round robin piles up on uneven request costs, plain hash mod N reshuffles almost every key when N changes
- Why power of two random choices is the default in modern proxies: nearly as good as least connections with no global state, and it avoids herding when many balancers share stale load data
- The load balancer itself must not be a single point of failure: redundant pairs, multiple addresses in DNS, anycast, or a managed multi-zone service
Code / implementation expected: Optional โ describing the algorithms precisely is enough; implementing one or two (as in the example) is a strong signal.