S2 - Build a Load Balancer
Tap the board to zoom inClick the board to zoom in
Lessons that use this board
S2 · BUILD A LOAD BALANCER
reverse proxy · round-robin · health checks · in Go
CLIENTS
:curl
LOAD BALANCER · :8080
pick next backend (round-robin):
i = (i+1) % len(pool)
skip any marked DOWN
BACKEND POOL
● :9001 UP
✗ :9002 DOWN (skipped)
● :9003 UP
health-check loop (goroutine):
every 2s → GET /health on each,
flip UP/DOWN on the result.
passive: also mark DOWN when a
real proxied request errors.
BACKENDS · your app, N copies
:9001
UP
:9002
DOWN
:9003
UP
skipped
round-robin
ONE REQUEST'S JOURNEY
1. client hits the LB at :8080
2. LB picks the next UP backend (round-robin) and skips DOWN ones
3. LB reverse-proxies the request → httputil.NewSingleHostReverseProxy
4. backend responds → LB streams it straight back to the client
5. in parallel, the health loop keeps the UP/DOWN list honest
README / RESUME LINE
“Built a concurrent HTTP load
balancer in Go: round-robin +
active/passive health checks +
reverse proxying (net/http/httputil),
zero-downtime backend failover.”
JARGON, DECODED
reverse proxy = a server that forwards a client's request to a backend and relays the reply; the client never talks to the backend directly.
round-robin = hand each new request to the next backend in turn → even spread with zero per-request state.
health check = a periodic probe; a backend that fails is marked DOWN and skipped until it passes again (self-healing).
active vs passive = active: LB pings on a timer. passive: LB marks a backend DOWN after a real request to it fails.
Saved in this browser only.