Load balancer interview answer: round robin, least connections, health checks and L4 vs L7 (Mock Interview Notes, Part 6)
The technical answer to 'design a load balancer' in a system design interview: round robin, weighted round robin, least connections, IP hash, power of two choices, /health checks with real defaults, slow start, sessions in Redis, the LB as a single point of failure, L4 vs L7, connection draining, and the live-match question.
By InternHack Team · · 13 min read · Interview Prep
Tatkal opens, you press Book, and you're logged out. Your ticket is gone. Somewhere a server died, and the system in front of it decided where your next request went. That system is the load balancer, and it's one of the most common system design interview questions.
These notes are the full technical answer, in the order a strong candidate gives it: what a load balancer is and why you need one, the standard algorithms, health checks with real default numbers, what happens to sessions, the load balancer as a single point of failure, L4 vs L7, and the follow-ups interviewers like. This is Part 6 of our Mock Interview series and a deeper, more technical take on the load balancer topic.
Facts come from the nginx, HAProxy, AWS, Envoy, Google and keepalived docs, plus a few company sources, all listed at the end. Where something is our own reasoning or arithmetic rather than a documented fact, we say so. Secondary or press-only figures are marked reported.
Why one big server is the weak answer
Flipkart says it handles "an enormous volume of 1.5 million requests per second when the sale opens" (Flipkart Stories, Oct 2023). That's 15 lakh requests every second.
The weak answer is "just buy a bigger server". Two problems: a single machine has a ceiling, and if it dies, everything is down. It's a single point of failure.
The strong answer is horizontal scaling: run many identical, stateless app servers, and put a load balancer in front of them on one public address. For every request, the load balancer:
- Picks a server using an algorithm (round robin by default, least connections when requests are uneven, a hash when the same user or key must hit the same server).
- Only sends to servers that pass health checks (active
/healthpings plus passive error watching). - Keeps working even if one server dies, because the others take the traffic.
Interview lesson: Lead with the shape (many stateless servers behind one entry point), then the algorithm, then health checks, then what can go wrong. That order is what interviewers listen for.
Sign up free to unlock the full notes
Aage ke sections free InternHack account ke saath khulte hain:
- The algorithms: what each does and when to use it
- Health checks: how the LB knows a server died
- Slow start, draining and deploys
- Sessions: why you got logged out
- What if the load balancer itself dies?
- L4 vs L7
- Edge cases and traps
- The reel's question: live match, users connected for hours. Round robin or least connections?
- How to answer this in an interview
Sources
- nginx upstream module: https://nginx.org/en/docs/http/ngx_http_upstream_module.html
- nginx proxy_next_upstream: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
- HAProxy backends and balance algorithms: https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/backends/
- HAProxy health checks: https://www.haproxy.com/documentation/haproxy-configuration-tutorials/reliability/health-checks/
- AWS ALB health checks: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html
- AWS ALB target group attributes (algorithms, draining, slow start, stickiness): https://docs.aws.amazon.com/elasticloadbalancing/latest/application/edit-target-group-attributes.html
- AWS ALB rule conditions: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/rule-condition-types.html
- AWS, how Elastic Load Balancing works: https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html
- AWS session management: https://aws.amazon.com/caching/session-management/
- Envoy load balancers: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/load_balancers
- Envoy panic threshold: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/panic_threshold
- Envoy outlier detection: https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/outlier_detection.proto
- Google Maglev (NSDI 2016): https://research.google/pubs/maglev-a-fast-and-reliable-software-network-load-balancer/
- Google SRE book, Load Balancing at the Frontend: https://sre.google/sre-book/load-balancing-frontend/
- Google Cloud load balancing overview: https://docs.cloud.google.com/load-balancing/docs/load-balancing-overview
- keepalived introduction: https://keepalived.readthedocs.io/en/latest/introduction.html
- Cloudflare Unimog (9 Sep 2020): https://blog.cloudflare.com/unimog-cloudflares-edge-load-balancer/
- GitHub GLB: https://github.blog/engineering/infrastructure/introducing-glb/
- Flipkart Stories Q&A (13 Oct 2023): https://stories.flipkart.com/innovation-customer-first-qna-jeyandran-venugopal
- Hotstar 5.9 crore concurrent viewers (Inc42, 19 Nov 2023, secondary): https://inc42.com/buzz/disneyhotstar-records-5-9-cr-concurrent-viewers-during-icc-world-cup-final
- DesignGurus, load balancer mistakes in interviews: https://www.designgurus.io/blog/load-balancer-mistakes-in-system-design-interviews
The detection-gap numbers (about 60 s, 2.5 minutes, 6 s, 1 in 4 requests) are our arithmetic on the documented defaults. The /health JSON shape, the college-NAT effect of IP hash, the P2C herding explanation and VRRP failover mechanics are standard knowledge, not quoted from a single doc. The Hotstar figure is a company statement reported by the press.