How vignol-yw/loadbalancer works
This Go TCP load balancer reads listener, backend, and strategy settings, accepts client connections, selects a backend, and proxies traffic bidirectionally. Routing supports round-robin and least-connections; the latter reads each backend server’s atomic active-connection count, which is updated during proxy handling. The README also describes high-concurrency operation and a Node.js workload demo; the sampled app implements health-check and delayed-work endpoints, but its deployment wiring is not shown.
Main entry points: main.go Load balancer process · server.go Backend server state · least-connections.go Least connections · balancing_strategy.go Strategy interface
Components 13
Configuration & startup
- Load balancer process
cmd/loadbalancer/main.go - Config loader
cmd/config/config.go - Load balancer config
loadbalancer.yaml - Strategy injector
cmd/dependencies/injection.go
Backend routing
- Strategy interface
internal/algorithms/balancing_strategy.go - Round robin
internal/algorithms/round-robin.go - Least connections
internal/algorithms/least-connections.go - Backend server state
internal/loadbalancer/server.go
TCP proxy
- Client connection
internal/loadbalancer/client.go - Connection handler
internal/loadbalancer/server.go
Other components
- Operator
- TCP clients
- Backend instances
Connections 20
- Operator → Load balancer process: starts
- Load balancer process → Config loader: loads settings
- Config loader → Load balancer config: reads
- Load balancer process → Strategy injector: selects strategy
- Strategy injector → Round robin: creates
- Strategy injector → Least connections: creates
- Round robin → Strategy interface: implements
- Least connections → Strategy interface: implements
- Load balancer process → Backend server state: creates servers
- Load balancer process → Strategy interface: registers servers
- Load balancer process → TCP clients: accepts connections
- Load balancer process → Strategy interface: selects backend
- Round robin → Backend server state: returns selection
- Least connections → Backend server state: reads counts
- Least connections → Backend server state: returns selection
- Load balancer process → Client connection: wraps connection
- Load balancer process → Connection handler: dispatches connection
- Connection handler → Backend server state: dials address
- Connection handler → Backend instances: proxies TCP traffic
- Connection handler → TCP clients: proxies TCP traffic