A production-style HTTP load balancer in Go with strategy switching, health checks, metrics, and integrated request rate limiting.
Current stable version: v1.0.0
License: MIT (redistributable)
- Multiple balancing strategies:
round-robinleast-connectionsweighted(smooth weighted round robin)
- Active health checks that mark unhealthy backends out of rotation
- YAML/JSON config loading
- Request logging
- Basic Prometheus-style metrics endpoint at
/metrics - Optional integration with
github.com/codestorm1875/ratelimiteras middleware
flowchart LR
C[Client] --> RL[Rate Limiter Middleware]
RL --> LB[Load Balancer Handler]
LB --> S{Strategy Engine}
S --> A[Backend A]
S --> B[Backend B]
S --> N[Backend N]
HC[Health Checker] --> A
HC --> B
HC --> N
LB --> M[Metrics Registry]
M --> P["/metrics"]
Request path summary:
- Incoming traffic enters optional rate limiting middleware.
- The balancer selects from healthy backends using configured strategy.
- Active health checks continuously mark backends in or out of rotation.
- Request and backend counters are exposed at
/metrics.
make runFor local development, start two mock backends in separate terminals first:
make backend-a
make backend-bThen start the load balancer:
make runNote: config.example.yaml has rate limiting disabled by default for smoother local smoke tests.
Enable rate_limit.enabled: true when you want to validate throttling behavior.
Copy config.example.yaml and adjust backend URLs.
The same config fields work for JSON and YAML files.
/proxied to selected upstream backend/metricsexposes counters and per-backend state/healthlocal balancer health endpoint
Standard workflow:
make checkUseful focused commands:
make test
make test-integration
make benchDirect Go commands remain available:
go mod tidy
go test ./...
go test -run TestIntegrationFailoverAndRecovery ./internal/lblb_requests_totallb_errors_totallb_ratelimited_totallb_active_requestslb_backend_up{name="..."}lb_backend_active_connections{name="..."}lb_backend_requests_total{name="..."}lb_backend_errors_total{name="..."}
This project demonstrates a layered architecture:
- Traffic shaping at the edge with strategy-based load distribution
- Automatic backend lifecycle management via active health checks
- Abuse control with fairness-aware rate limiting middleware
- Observability through structured logs and scrape-friendly metrics
- Semantic versioning is used for stable releases.
- The current release tag is
v1.0.0. - Release notes are tracked in
CHANGELOG.md.