🚀 A lightweight, dynamic, and customizable Load Balancer built in Go (Golang) with multiple routing strategies, active health checks, real-time dashboard, and live backend management.
BalancerX supports four load-balancing algorithms (configurable via JSON):
- Round Robin — simple cyclical distribution
- Weighted Round Robin — distributes traffic relative to server weight
- Least Connections — sends requests to the server with the fewest active connections
- IP Hash — sticky sessions based on client IP
- Add/remove backend servers without restarting the load balancer
- Fully JSON-driven configuration
- Periodically probes each backend’s
/health(or custom) endpoint - Automatically removes unhealthy backends from rotation
- Restores them once they recover
UI available at:
http://localhost:8080/ui
View:
- Server health (green/red)
- Active connections
- Traffic routing
- Add/remove servers live
sync.RWMutexfor read-optimized backend poolsync/atomicfor counters (active requests, RR index)- Goroutines for parallel health checks & proxying
If a backend fails during a request:
- Proxy detects failure
- Tracks retry attempts
- Automatically routes the request to next healthy server
/balancerx
├── config.json # Dynamic configuration file
├── main.go # Entry point, server, API, dashboard
├── models.go # Backend, ServerPool structures
├── strategies.go # Round Robin, WRR, LC, IP-Hash algorithms
└── utils.go # Health checks, config loader
/backend
└── main.go # Simple dummy backend for testing
- Go 1.18+
git clone https://github.com/shubhamc1947/balancerx.git
cd balancerxEdit balancerx/config.json:
{
"server_port": ":8080",
"health_check_interval": "10s",
"lb_strategy": "least-connection",
"backends": [
{
"url": "http://localhost:8081",
"weight": 1,
"health_path": "/"
}
]
}Supported Strategies:
| Strategy | Value |
|---|---|
| Round Robin | "round-robin" |
| Weighted Round Robin | "weighted-round-robin" |
| Least Connections | "least-connection" |
| IP Hash | "ip-hash" |
This starts 3 test backends on ports 8081, 8082, 8083:
go run backend/main.gogo run ./balancerxOpen:
http://localhost:8080/ui
From the control panel you can:
- ✔ See backend status
- ✔ Monitor live connections
- ✔ Add a new server
- ✔ Remove a server
GET /api/backends
POST /api/backends
Example:
curl -X POST http://localhost:8080/api/backends \
-d '{"url": "http://localhost:8084", "weight": 2, "health_path": "/"}'DELETE /api/backends
- 🧵 Goroutines — non-blocking request forwarding & health checks
- 🔐 Atomic Counters — RR index, active connections
- 🔒 RWMutex — safe concurrent backend management
- Custom
ReverseProxyerror handler - Automatic retries to next healthy backend
- Context-aware retry limit
- Weighted Least Connections
- Prometheus
/metricsexporter - HTTPS/TLS termination
- Rate limiting
This project is licensed under the MIT License.