Command Palette

Search for a command to run...

PHASE 9Intermediate ~7 min· topic 4 of 9

Topic 9.4

Load Balancers

In one line

Round Robin, Least Connections, IP Hash, health checks — the front door of every scaled system.

0/9 · 0%

Think of it like this

A bank with multiple teller counters and a person at the entrance directing each new customer to whichever counter is free or has the shortest line, instead of everyone crowding one teller.

Key ideas

  1. 01

    L4 (transport): routes by IP/port, raw TCP — fast, no content awareness.

  2. 02

    L7 (application): inspects HTTP (paths, headers, cookies) — routing, retries, auth-friendliness at the cost of parsing.

  3. 03

    Round Robin: even rotation; simplest; ignores load and capacity differences.

  4. 04

    Least Connections: send to the node with fewest active connections — better for uneven request lengths.

  5. 05

    IP Hash: consistent node per client IP — session affinity 'for free' (with the stickiness caveats).

  6. 06

    Health checks: LB stops sending to a failing node (HTTP /healthz, TCP probe) — THE load-balancer superpower.

  7. 07

    DNS + LB topology: DNS → LB VIP → instance pool. Multiple LBs for HA.

Java / Spring map

  • →

    Spring Cloud Gateway / Ribbon-lite; actuator /health for LB probes.

Code & diagrams

L4 vs L7 load balancingdiagram
Rendering diagram…
LoadBalancer.mdmarkdown

Strategy table — read it as a decision tree.

Strategy           | picks                       | when
Round Robin        | next in rotation            | equal-capacity, equal-cost requests
Least Connections  | fewest active               | mixed long/short workloads
IP Hash            | hash(clientIp)             | affinity without sticky cookies
Weighted RR        | rotation × capacity         | heterogeneous nodes

Plus, always:
- health checks (L7 GET /healthz, tolerated 2/3 to remove)
- idle connection draining before node shutdown

Explain without notes

01

Why does IP Hash beat Round Robin for a legacy app that needs session affinity — and what's its weakness?

Practice

01

Specify the LB (L4 vs L7) for: TCP game server, HTTP API with rate limits by IP, gRPC internal service.

Trade-offs

  • ↔

    L7 gives routing power but adds latency + becomes a possible bottleneck itself — keep it thin.

Run it in production

Completion checklist

  • I can pick an LB strategy by workload and always mention health checks.

Back to phase