ConnX is a high-performance, lightweight HTTP reverse proxy and load balancer written in Go. It leverages the gnet framework for efficient network operations and provides features like health checking and round-robin load balancing.
- High-performance HTTP reverse proxy - Built on gnet for efficient network operations
- Multiple load balancing algorithms:
- Round-robin (default)
- Weighted round-robin (distribute traffic by backend weight)
- Least connections (route to backend with fewest active connections)
- Hot reload configuration - Update settings, backends, and algorithms without restart
- Circuit breaker pattern - Automatic failure detection and recovery
- Rate limiting - Global or per-IP request throttling with token bucket algorithm
- Graceful shutdown - Proper connection draining on SIGTERM/SIGINT
- Active health checking - Periodic backend health verification
- Real-time metrics - Prometheus-compatible
/metricsendpoint - Zero-downtime updates - Add/remove backends dynamically without dropping connections
# Clone the repository
git clone https://github.com/ODudek/ConnX.git
cd ConnX
# Start with Docker Compose (includes example backends)
docker-compose up -d
# Test the setup
curl http://localhost:8080
curl http://localhost:8080/metricsDownload the latest release from GitHub Releases:
# Linux
wget https://github.com/ODudek/ConnX/releases/latest/download/connx-linux-amd64
chmod +x connx-linux-amd64
./connx-linux-amd64 -config=config.yaml
# macOS
wget https://github.com/ODudek/ConnX/releases/latest/download/connx-darwin-amd64
chmod +x connx-darwin-amd64
./connx-darwin-amd64 -config=config.yamlgit clone https://github.com/ODudek/ConnX.git
cd ConnX
make build
./bin/proxy -config=configs/config.yamlCreate a config.yaml file with the following structure:
server:
port: 8080
host: "0.0.0.0"
shutdownTimeout: 30 # seconds for graceful shutdown
backends:
- url: "http://backend1:8080"
weight: 1
- url: "http://backend2:8080"
weight: 2 # Gets 2x more traffic
- url: "http://backend3:8080"
weight: 1
loadBalancing:
algorithm: "round-robin" # Options: round-robin, weighted-round-robin, least-connections
healthCheck:
interval: 30 # seconds
timeout: 5 # seconds
circuitBreaker:
enabled: true
maxFailures: 5 # Open circuit after N failures
timeout: 60 # Seconds before trying half-open state
resetTimeout: 30 # Seconds in half-open state
halfOpenSuccess: 2 # Successes needed to close circuit
rateLimit:
enabled: false # Enable/disable rate limiting
requestsPerSec: 100 # Requests per second allowed
burst: 200 # Maximum burst size
perIP: false # true for per-IP, false for globalConnX supports hot reload - you can modify the configuration file while the server is running, and changes will be applied automatically without restart:
What can be reloaded:
- Add/remove/update backends
- Change backend weights
- Switch load balancing algorithms
- Update rate limiting settings
- Modify health check intervals
- Enable/disable circuit breaker
How it works:
- Edit your
config.yamlfile - Save the changes
- ConnX automatically detects the change and reloads (within ~2 seconds)
- Changes are applied with zero downtime
Example:
# Start the proxy
./bin/proxy -config=configs/config.yaml
# In another terminal, edit the config
vim configs/config.yaml # Add a new backend
# Check logs - you'll see:
# Config file changed, reloading...
# Adding new backend: http://backend4:8080 (weight: 1)
# Configuration reloaded successfullyConnX exposes Prometheus-compatible metrics at /metrics:
curl http://localhost:8080/metricsconnx_requests_total- Total HTTP requests by method and statusconnx_errors_total- Total error countconnx_response_time_seconds- Response time statistics (avg, p95, p99)connx_backend_up- Backend health status (1=up, 0=down)connx_active_connections- Current active connectionsconnx_uptime_seconds- Server uptimeconnx_requests_per_second- Current requests per second
# Run with default config
./connx
# Run with custom config
./connx -config=/path/to/config.yaml
# Docker
docker run -p 8080:8080 -v $(pwd)/config.yaml:/app/configs/config.yaml odudek/connx:latestSee configs/examples/ for various configuration examples:
basic.yaml- Minimal setupproduction.yaml- Production-ready configurationdevelopment.yaml- Development environmentmonitoring.yaml- With Prometheus integrationwith-rate-limiting.yaml- Rate limiting enabledweighted-round-robin.yaml- Weighted load balancingleast-connections.yaml- Least connections algorithmfull-features.yaml- All features enabled
If not specified in the config file, the following default values are used:
- Server port: 8080
- Server host: "0.0.0.0"
- Shutdown timeout: 30 seconds
- Health check interval: 30 seconds
- Health check timeout: 5 seconds
- Load balancing algorithm: round-robin
- Backend weight: 1
- Circuit breaker: enabled (5 failures, 60s timeout)
- Rate limiting: disabled
This project uses GitHub Actions for Continuous Integration and Deployment:
- Runs tests
- Performs linting using golangci-lint
- Builds the application
- Runs on every push to main and pull requests
- Triggered by tags starting with 'v'
- Creates releases with binaries for multiple platforms
- Builds and pushes Docker images to Docker Hub
- Generates release notes automatically
Latest images are available on Docker Hub:
docker pull odudek/connx:latestConnX consists of several key components:
- Proxy Server: Handles incoming connections and forwards requests to backends
- Server Pool: Manages the collection of backend servers with active connection tracking
- Health Checker: Monitors backend server health with configurable intervals
- Load Balancer: Distributes requests using configurable algorithms (round-robin, weighted, least-connections)
- Circuit Breaker: Prevents cascade failures by temporarily disabling unhealthy backends
- Rate Limiter: Token bucket-based rate limiting (global or per-IP)
- Config Watcher: Monitors configuration file and triggers hot reload on changes
ConnX is built with performance in mind:
- Uses gnet for efficient network operations
- Tracks active connections for optimal load distribution
- Minimizes memory allocations
- Supports multicore processing
- Circuit breaker prevents wasted requests to failing backends
- Token bucket rate limiting for efficient request throttling
- Hot reload with zero downtime - no need to restart for config changes
We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
make test) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install dependencies
go mod download
# Run tests
make test
# Run linting
golangci-lint run
# Build
make buildThis project is licensed under the MIT License - see the LICENSE file for details.
- π Documentation
- π Report Issues
- π‘ Feature Requests
- π¬ Discussions
- gnet - High-performance, lightweight, non-blocking, event-driven networking framework
- All contributors who help make ConnX better