How abdulrahman-tayara/go-lb works
Go-LB is an HTTP reverse proxy/load balancer. Its main workflow loads JSON/YAML settings, builds a routing strategy and load balancer, optionally wraps it in rate limiting, then accepts requests and proxies them to a selected backend. A background health checker probes configured backend health URLs and updates the load balancer when server status changes. The README also documents content-based routing, TLS, and several balancing algorithms. Edges reflect the shown startup and runtime calls; algorithm wiring beyond the factory call is not expanded where source relationships were not shown.
Main entry points: load_balancer.go Load balancer · main.go Process startup · factory.go Strategy factory · checker.go Health checker
Components 20
Startup and config
- Config loader
configs/configs.go - Process startup
main.go - HTTP server
main.go
Request handling
- Rate-limit middleware
ratelimiter/buckettokens/middleware.go - Token bucket
ratelimiter/buckettokens/limiter.go - Bucket state
ratelimiter/buckettokens/bucket.go - Load balancer
lb/load_balancer.go
Balancing algorithms
- Strategy factory
strategy/factory.go - Strategy interface
strategy/strategy.go - Round robin
strategy/round_robin.go - Weighted round robin
strategy/weighted_round_robin.go - Least connections
strategy/least_connections.go - Random strategy
strategy/random.go - Sticky sessions
strategy/sticky_session.go
Health monitoring
- Health checker
healthcheck/checker.go - Observer contract
healthcheck/observer.go
Backend and routing models
- Server model
models/server.go - Content routing
models/routing.go
Other components
- HTTP client
- Backend servers
Connections 24
- HTTP client → HTTP server: sends request
main.go - Process startup → Config loader: loads settings
main.go - Process startup → Strategy factory: selects strategy
main.go - Process startup → Load balancer: constructs
main.go - Process startup → Health checker: starts checks
main.go - Process startup → Rate-limit middleware: optionally wraps
main.go - Process startup → HTTP server: serves handler
main.go - HTTP server → Rate-limit middleware: dispatches to
main.go - Rate-limit middleware → Token bucket: limits by key
ratelimiter/buckettokens/middleware.go - Rate-limit middleware → Load balancer: forwards allowed
ratelimiter/buckettokens/middleware.go - Load balancer → Backend servers: proxies request
lb/load_balancer.go - Load balancer → Strategy interface: selects server
lb/load_balancer.go - Load balancer → Content routing: matches rules
lb/load_balancer.go - Load balancer → Server model: uses server data
lb/load_balancer.go - Strategy factory → Round robin
- Strategy factory → Weighted round robin
- Strategy factory → Least connections
- Strategy factory → Random strategy
- Strategy factory → Sticky sessions
- Health checker → Backend servers: probes health URL
README.md - Health checker → Observer contract: notifies changes
healthcheck/checker.go - Health checker → Load balancer: updates availability
- Config loader → Server model: decodes servers
configs/configs.go - Config loader → Content routing: decodes routes
configs/configs.go