A high-performance Layer 4 (TCP) load balancer implemented in Go.
-
Multiple Load Balancing Algorithms
- Round Robin
- Least Connections (TODO)
-
Health Checking
- Automatic backend health monitoring
- Configurable check intervals
- Unhealthy backend removal
-
Connection Pooling
- Efficient connection reuse
- Configurable pool sizes
- Connection lifecycle management
-
Configuration Management
- YAML-based configuration
- Runtime configuration reloading (TODO)
├── cmd/
│ └── main.go # Application entry point
├── internal/
│ ├── balancer/
│ │ ├── balancer.go # Core load balancer logic
│ │ └── algorithms.go # Load balancing algorithms
│ ├── backend/
│ │ └── backend.go # Backend server management
│ ├── health/
│ │ └── checker.go # Health checking functionality
│ └── config/
│ └── config.go # Configuration management
├── pkg/
│ └── pool/
│ └── pool.go # Connection pooling
├── configs/
│ └── config.yaml # Sample configuration
├── go.mod
├── go.sum
└── README.md
The load balancer is configured using a YAML file. See configs/config.yaml for an example.
loadbalancer.listen_address: Address to listen on (e.g., ":8080")loadbalancer.algorithm: Load balancing algorithm ("round_robin", "least_connections")backends: List of backend servers with address and porthealthcheck.interval: How often to check backend healthhealthcheck.timeout: Timeout for health checks
-
Build the application:
go build -o l4-load-balancer ./cmd
-
Run with default configuration:
./l4-load-balancer
-
Run with custom configuration:
./l4-load-balancer -config configs/config.yaml
- Go 1.19 or later
go test ./...- Implement the
Algorithminterface ininternal/balancer/algorithms.go - Add the algorithm to the algorithm factory/registry
- Update configuration options
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License (add your license details)
- Implement least connections algorithm
- Add weighted round robin
- Add SSL/TLS termination
- Add metrics and monitoring
- Add graceful shutdown
- Add configuration hot-reloading
- Add rate limiting
- Add connection limiting per backend
- Add logging configuration
- Add Docker support