What is a load balancer and how does it distribute traffic across servers?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
A load balancer is a traffic dispatcher sitting in front of a pool of servers. It spreads requests using algorithms (round-robin, least connections, IP hash), hides server failures with health checks, and provides a single entry point. Layer 4 (transport) balances by IP/port; Layer 7 (application) can route by URL, headers, or cookies for smarter distribution.
Detailed explanation
A load balancer (LB) is the single public IP clients hit; behind it sits a target group of interchangeable servers. Core job: distribute work so no single server drowns while others idle. Algorithms matter: round-robin cycles through servers evenly (great for equal-capacity, short-lived requests); least-connections sends to the fewest active requests (better for mixed workloads); IP-hash sticks a client to one server (preserves local session caches, useful before you externalize state); weighted variants account for unequal server capacity. Health checks are essential — the LB pings each target periodically and stops routing to any that fail, providing failover transparently. Layer 4 LBs (e.g., NLB, HAProxy in TCP mode) forward by source/destination IP and port — fast, cheap, but blind to content. Layer 7 LBs (e.g., ALB, NGINX, HAProxy in HTTP mode) inspect the HTTP layer and can route /api/* to one pool and /static/* to another, terminate SSL, inject headers, and cache responses. In the cloud, managed LBs (AWS ALB/NLB, GCP CLB) auto-scale themselves and integrate with auto-scaling groups. Global load balancing adds DNS-level or anycast routing to direct users to the nearest regional cluster. Watch for: the LB itself becoming a bottleneck (managed LBs solve this) and the thundering-herd effect when a recovered server is suddenly flooded.
Example
Client → DNS (api.example.com → 203.0.113.10)
↓
AWS Application Load Balancer (Layer 7)
├─ /api/users/* → Target group: user-service (3 instances)
├─ /api/orders/* → Target group: order-service (5 instances)
└─ /static/* → S3 / CDN
Health check: GET /health every 30s on each target.Interview tip
Name one Layer 4 and one Layer 7 example with a concrete reason to choose each. Then mention health checks — that is the detail that separates a surface answer from one that has actually operated a system.
Common mistakes
- Forgetting health checks, which are what make failover automatic.
- Not distinguishing Layer 4 from Layer 7.
- Treating the load balancer as invisible — it needs redundancy too (managed LBs handle this).