Overview
UltraBalancer supports multiple load balancing algorithms, each optimized for different use cases. Choosing the right algorithm is crucial for optimal performance and reliability.Available Algorithms
Round Robin
Equal distribution in sequential order
Least Connections
Routes to backend with fewest active connections
IP Hash
Consistent hashing based on client IP
Weighted Round Robin
Distribution based on backend weights
Random
Random backend selection
Round Robin
How It Works
Distributes requests sequentially across all healthy backends in a circular fashion.Best For
- Homogeneous backends with similar capacity
- Stateless applications where any backend can handle any request
- Simple deployments where you want equal distribution
Usage
CLI
Config File
Characteristics
Pros
- Simple and predictable
- Even distribution over time
- Low computational overhead
- No state required
Cons
- Doesn’t consider backend load
- May unevenly distribute long-running requests
- Not suitable for heterogeneous backends
Least Connections
How It Works
Routes each request to the backend with the fewest active connections, ensuring optimal load distribution.Best For
- Long-lived connections (WebSockets, streaming)
- Variable request durations
- Real-time load balancing
- Heterogeneous workloads
Usage
CLI
Config File
Characteristics
Pros
- Dynamic load distribution
- Handles variable request times well
- Optimal for long-lived connections
- Prevents backend overload
Cons
- Slight computational overhead
- Requires connection tracking
- May cause “thundering herd” on restart
IP Hash
How It Works
Uses consistent hashing on the client’s IP address to always route the same client to the same backend.Best For
- Session persistence without cookies
- Stateful applications requiring sticky sessions
- Cache locality optimization
- WebSocket applications
Usage
CLI
Config File
Characteristics
Pros
- Session persistence without cookies
- Excellent cache hit rates
- Predictable routing
- No server-side session storage needed
Cons
- Uneven distribution if client IPs skewed
- NAT/proxy may group many clients
- Backend changes disrupt sessions
- Not suitable for APIs behind CDN
Weighted Round Robin
How It Works
Distributes requests based on assigned weights, allowing prioritization of more powerful backends.Best For
- Heterogeneous backends with different capacities
- Phased rollouts (canary deployments)
- Multi-zone deployments (prefer same-zone backends)
- Hardware variations (different CPU/memory)
Usage
CLI
Config File
Characteristics
Pros
- Handles heterogeneous backends
- Perfect for capacity planning
- Enables canary deployments
- Flexible traffic control
Cons
- Requires weight tuning
- More complex configuration
- Static weights don’t adapt to load
Weight Examples
Random
How It Works
Selects a backend randomly for each request.Best For
- Testing and development
- Stateless microservices
- Simple deployments
- Load testing scenarios
Usage
CLI
Config File
Characteristics
Pros
- Simple implementation
- No state required
- Even distribution over time
- Unpredictable (good for testing)
Cons
- Short-term imbalance possible
- Not deterministic
- Rarely optimal for production
Algorithm Comparison
| Algorithm | Session Persistence | Load Awareness | Complexity | Best Use Case |
|---|---|---|---|---|
| Round Robin | ❌ | ❌ | Low | Homogeneous backends |
| Least Connections | ❌ | ✅ | Medium | Variable workloads |
| IP Hash | ✅ | ❌ | Medium | Stateful apps |
| Weighted RR | ❌ | ⚠️ Static | Medium | Heterogeneous backends |
| Random | ❌ | ❌ | Low | Testing |
Choosing the Right Algorithm
1
Assess Your Requirements
- Do you need session persistence? → IP Hash
- Do backends have different capacities? → Weighted Round Robin
- Do requests have variable durations? → Least Connections
- Simple stateless app with equal backends? → Round Robin
2
Consider Your Traffic
- WebSocket/long-lived connections? → Least Connections
- High request rate with short responses? → Round Robin
- Users need consistent backend? → IP Hash
3
Test and Monitor
Start with Round Robin and monitor:
- Backend utilization
- Response times
- Error rates
- Connection distribution