Load Balancing with Gate
Gate provides sophisticated load balancing capabilities at two distinct levels:- Frontend Load Balancing - Distributing player connections across multiple Gate proxy instances
- Backend Load Balancing - Distributing connections from Gate to backend Minecraft servers
Architecture Overview
Frontend Load Balancing
Distribute incoming player connections across multiple Gate instances for horizontal scaling and high availability.Method 1: Gate Connect (Recommended)
The simplest approach uses Gate Connect’s built-in load balancing:config.yml (All instances)
- Configure first Gate instance with Connect
- Copy the
connect.jsontoken file - Deploy additional instances with the same endpoint name and token
- Zero configuration load balancing
- Automatic health checks
- Built-in failover
- No additional infrastructure required
- Home servers without static IPs
- Development and testing environments
- Quick production deployments
- Dynamic infrastructure (cloud, containers)
Method 2: Kubernetes Service
For cloud-native deployments, use Kubernetes native load balancing:gate-deployment.yaml
sessionAffinity: ClientIP- Ensures players reconnect to same instancereplicas: 3- Run three Gate instances- Resource limits prevent resource starvation
- Native cloud integration
- Health check automation
- Auto-scaling capabilities
- Enterprise-grade reliability
Method 3: TCP Load Balancer (HAProxy/nginx)
For traditional infrastructure, use dedicated TCP load balancers:- HAProxy
- nginx
haproxy.cfg
leastconn- Routes to instance with fewest connectionsstick-table- Session persistence based on IP- Health checks with automatic failover
- Configurable timeouts for long-lived connections
Backend Load Balancing
Gate Lite mode provides powerful load balancing strategies for distributing connections to backend servers.Enabling Lite Mode
Lite mode transforms Gate into a lightweight reverse proxy with advanced routing:config.yml
Load Balancing Strategies
Gate Lite supports five load balancing strategies, each optimized for different scenarios:1. Sequential (Default)
Behavior: Always tries the first backend, falling back to subsequent servers only on failure.- Primary/backup server configurations
- Failover without load distribution
- Cost optimization (keep backup servers idle)
2. Random
Behavior: Randomly selects a backend for each new connection.- Simple load distribution
- Stateless server pools
- Equal-capacity servers
- Very fast selection (no state tracking)
- Good distribution over many connections
- No session affinity
3. Round-Robin
Behavior: Cycles through backends in order, distributing connections evenly.- Evenly matched server capacity
- Predictable load distribution
- Multiple identical server instances
- Per-route counter tracks current position
- Independent round-robin state for each route
- Wraps around when reaching the end
4. Least-Connections
Behavior: Routes to the backend with the fewest active connections.- Variable connection durations
- Mixed server capacities
- Optimal resource utilization
- Tracks active connections per backend
- Increments counter when connection established
- Decrements when connection closes
- Selects backend with minimum count
5. Lowest-Latency
Behavior: Routes to the backend with the fastest response time.- Geographically distributed backends
- Performance-critical routing
- Heterogeneous server hardware
- Measures ping/status response time
- Caches latency data (3-minute TTL)
- Selects backend with lowest recorded latency
- Unknown latencies are measured first
Multi-Route Configuration
Combine multiple routes with different strategies for complex deployments:config.yml
Advanced Features
Fallback Status Responses
Provide custom status responses when all backends are offline:- Professional appearance during maintenance
- Custom messaging for players
- Prevents generic “connection refused” errors
Dynamic Backend Substitution
Use hostname parameters in backend addresses:- Kubernetes service discovery
- Dynamic server pools
- DNS-based routing
Caching and Performance
Optimize performance with ping caching:cachePingTTL: 60s- Cache for 60 seconds (reduces backend load)cachePingTTL: -1- Disable caching (always ping backends)cachePingTTL: 0or omitted - Use default (10 seconds)
- Reduced latency for server list pings
- Lower load on backend servers
- Better player experience
Classic Mode Load Balancing
Outside of Lite mode, Gate’s classic mode supports basic load balancing through thetry list and forcedHosts:
config.yml
- Players connecting via
lobby.example.comtrylobby1first, fallback tolobby2 - Uses sequential strategy (no round-robin or least-connections)
- Suitable for simple deployments
For advanced load balancing strategies (round-robin, least-connections, etc.), use Lite mode instead of classic mode.
Monitoring and Metrics
Track load balancing effectiveness:Connection Distribution
Monitor which backends receive connections:Health Checks
Gate automatically health checks backends during connection attempts:Performance Metrics
For lowest-latency strategy, monitor cached latencies:Best Practices
Match Strategy to Workload
- Round-robin for equal-capacity servers
- Least-connections for variable session lengths
- Lowest-latency for geo-distributed deployments
- Sequential for primary/backup scenarios
Enable Fallback Responses
Always configure fallback status responses to provide professional UX during outages.
Use Session Affinity
Configure frontend load balancers with session affinity (sticky sessions) to keep players on the same Gate instance.
Monitor Backend Health
Implement external monitoring to detect backend failures before players experience issues.
Troubleshooting
Uneven load distribution
Uneven load distribution
Possible Causes:
- Frontend load balancer not using sticky sessions
- Long-lived connections (older connections remain on one server)
- Backend capacity differences
- Use
least-connectionsstrategy instead ofround-robin - Configure session affinity on frontend load balancer
- Ensure backends have similar capacity
Players connecting to offline servers
Players connecting to offline servers
Possible Causes:
- Backend went offline after selection
- Health check caching issues
- Gate automatically tries next backend in list
- Configure
fallbackstatus response - Reduce
cachePingTTLfor faster failure detection
Lowest-latency not working as expected
Lowest-latency not working as expected
Possible Causes:
- Latency cache expired or not populated
- Network conditions changed
- Backends have similar latencies
- Enable debug logging to see latency values
- Verify backends are responding to status requests
- Consider
least-connectionsif latencies are similar
Performance Tuning
Connection Timeouts
Adjust timeouts for backend connections:config.yml
- Lower
connectionTimeoutfor faster failover (2-5 seconds) - Higher
readTimeoutfor Forge/modded servers (30-60 seconds)
Resource Limits
Set appropriate resource limits for Gate instances:kubernetes
- 512Mi-1Gi memory for small servers (< 100 players)
- 1Gi-2Gi memory for medium servers (100-500 players)
- 2Gi+ memory for large servers (500+ players)
Related Resources
Gate Connect
Use Connect for automatic frontend load balancing
Failover Configuration
Configure automatic failover and recovery
Kubernetes Deployment
Deploy Gate on Kubernetes with native load balancing
Lite Mode Guide
Learn more about Gate Lite mode capabilities

