How lekhanj/load-balancer works
This is a learning-oriented HTTP load balancer: it accepts client requests, selects a healthy backend using a configured strategy, and reverse-proxies the request. Startup loads configuration, initializes backend state, and starts periodic health checks; request handling resolves a client key, chooses a server, tracks active connections, and reuses a proxy. The README also documents four interchangeable routing strategies and a Python HTTP backend. The graph follows the sampled Go entry point and runtime modules; the backend’s role is documented and its implementation is present in the tree.
Main entry points: main.go Load Balancer Entry · server.go Backend Server State · balancer.go Strategy Dispatcher · proxy_pool.go Proxy Pool
Components 14
Startup and Config
- Load Balancer Entry
cmd/load-balancer/main.go - Runtime Config
cmd/load-balancer/config.json - Config Model
internal/balancer/config.go
Routing and State
- Strategy Dispatcher
internal/balancer/balancer.go - Round Robin
internal/algorithms/round_robin.go - Weighted Round Robin
internal/algorithms/weighted_round_robin.go - Least Connections
internal/algorithms/least_connections.go - IP Hash
internal/algorithms/ip_hash.go - Backend Server State
internal/balancer/server.go - Health Checker
internal/balancer/health_check.go - Proxy Pool
internal/balancer/proxy_pool.go - Reverse Proxy
internal/balancer/proxy_pool.go
Backend Services
- Python HTTP Backend
server/server.py
Other components
- HTTP Client
Connections 28
- HTTP Client → Load Balancer Entry: sends request
- Load Balancer Entry → Runtime Config: reads
- Load Balancer Entry → Config Model: decodes config
- Load Balancer Entry → Round Robin: selects strategy
- Load Balancer Entry → Weighted Round Robin: selects strategy
- Load Balancer Entry → Least Connections: selects strategy
- Load Balancer Entry → IP Hash: selects strategy
- Load Balancer Entry → Strategy Dispatcher: initializes
- Load Balancer Entry → Backend Server State: creates servers
- Load Balancer Entry → Health Checker: starts checks
- Load Balancer Entry → Proxy Pool: creates pool
- Load Balancer Entry → Strategy Dispatcher: requests selection
- Strategy Dispatcher → Round Robin: dispatches Next
- Strategy Dispatcher → Weighted Round Robin: dispatches Next
- Strategy Dispatcher → Least Connections: dispatches Next
- Strategy Dispatcher → IP Hash: dispatches Next
- Round Robin → Backend Server State: checks health
- Weighted Round Robin → Backend Server State: checks health and weights
- Least Connections → Backend Server State: reads health and counts
- IP Hash → Backend Server State: checks health
- Health Checker → Backend Server State: updates health
- Health Checker → Python HTTP Backend: sends HEAD
- Load Balancer Entry → Backend Server State: tracks connections
- Load Balancer Entry → Proxy Pool: gets proxy
- Proxy Pool → Backend Server State: reads backend URL
- Proxy Pool → Reverse Proxy: creates and reuses
- Load Balancer Entry → Reverse Proxy: serves request
- Reverse Proxy → Python HTTP Backend: forwards HTTP