A high-performance, feature-rich HTTP/S load balancer built from scratch in Go
Educational β’ Modular β’ Production-Ready
- π Advanced Go Load Balancer
β οΈ Beta Release: This project is currently in beta and actively under development. Features and APIs may evolve.
This project showcases an advanced HTTP/S load balancer implementation in Go, designed as both an educational resource and a practical networking infrastructure component. Built with modularity and extensibility in mind, it demonstrates core concepts of distributed systems, load balancing, and network programming.
|
|
- HTTP/S Reverse Proxying with high performance
- Graceful Shutdown for clean terminations
- Observability Integration with logging, metrics, and tracing
- Modular Architecture for easy extension
The project follows the standard Go project layout:
go-loadbalancer/
βββ π cmd/go-lb/ # Application entry point
β βββ main.go # Main application file
βββ π api/ # API definitions
β βββ http/v1/ # HTTP API version 1
βββ βοΈ configs/ # Configuration files and templates
β βββ config.go # Configuration structures
β βββ loader.go # Configuration loading logic
βββ π internal/ # Internal business logic
β βββ app/ # Application initialization
β βββ admin/ # Admin interface
β βββ backend/ # Backend server management
β βββ healthcheck/ # Health checking system
β βββ logging/ # Structured logging
β βββ middleware/ # HTTP middleware
β βββ monitoring/ # Metrics and monitoring
β βββ serverpool/ # Backend pools & algorithms
β βββ routing/ # Request routing engine
β βββ policy/ # Policy enforcement
β βββ tracing/ # Distributed tracing
β βββ handler/ # Core request handlers
βββ π¦ pkg/ # Reusable utilities
βββ π§ͺ test/ # Additional test applications
βββ π§ scripts/ # Scripts for various tasks
βββ π’ deployments/ # Deployment configurations
β βββ docker/ # Docker-related files
βββ π tools/ # Tools and utilities
β βββ k6/ # K6 load testing scripts
βββ π docs/ # Documentation files
- Go 1.23+ installed on your system
- Backend services to load balance (for testing)
# Clone the repository
git clone https://github.com/rixtrayker/go-loadbalancer.git
# Navigate to project directory
cd go-loadbalancer
# Build the project
go build -o build/go-lb ./cmd/go-lb
# Start with default configuration
./build/go-lb
# Or specify a config file
./build/go-lb --config configs/config.yml
The load balancer uses a flexible configuration system supporting:
- π― Listener Settings: Address, port, TLS configuration
- π Backend Pools: Server groups with load balancing algorithms
- π Health Checks: Monitoring intervals, timeouts, and probe types
- π£οΈ Routing Rules: Complex request matching and forwarding
- π Policies: Rate limiting, transformations, and access control
- π Monitoring: Logging, metrics, and tracing configuration
server:
address: ":8080"
backend_pools:
- name: "web-servers"
algorithm: "round_robin"
backends:
- url: "http://localhost:3001"
weight: 1
- url: "http://localhost:3002"
weight: 2
health_check:
path: "/health"
interval: "30s"
timeout: "5s"
routing_rules:
- match:
host: "example.com"
path: "/api/*"
target_pool: "web-servers"
policies:
- rate_limit: "100/minute"
monitoring:
prometheus:
enabled: true
path: "/metrics"
port: 9090
tracing:
enabled: true
service_name: "go-loadbalancer"
endpoint: "localhost:4317"
- π§ Modularity: Clean separation of concerns
- π Extensibility: Plugin-based architecture
- β‘ Performance: Optimized for high throughput
- π‘οΈ Reliability: Robust error handling and recovery
Component | Purpose |
---|---|
Router | Intelligent request routing and matching |
Server Pool | Backend management and load balancing |
Health Checker | Continuous backend monitoring |
Policy Engine | Request/response transformation and control |
Admin Interface | Runtime configuration and monitoring |
The load balancer includes comprehensive observability features:
- Structured JSON logging with zap
- Configurable log levels and formats
- Trace context correlation
- Prometheus metrics for all components
- Request/response metrics
- Backend health and performance metrics
- System resource usage
- OpenTelemetry integration
- Distributed tracing support
- Trace context propagation
- Span attributes for detailed analysis
This project serves as an excellent learning resource, demonstrating several important concepts and best practices in Go development:
- Standard Go project layout
- Modular architecture with clean interfaces
- Effective use of middleware patterns
- Comprehensive observability implementation
- Advanced configuration management
- Multiple load balancing algorithms
- Policy-based request handling
We welcome contributions! See the Contributing Guide for more information.
- gRPC Load Balancing: Support for gRPC protocols
- Docker Integration: Containerized deployment
- Kubernetes Support: Native K8s integration
- WebSocket Proxying: Real-time connection support
- Circuit Breaker: Fault tolerance patterns
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by rixtrayker
β Star this repo if you find it helpful! β