Skip to main content

Load Balancing with Gate

Gate provides sophisticated load balancing capabilities at two distinct levels:
  1. Frontend Load Balancing - Distributing player connections across multiple Gate proxy instances
  2. Backend Load Balancing - Distributing connections from Gate to backend Minecraft servers
This dual-layer approach enables highly scalable and resilient Minecraft network architectures.

Architecture Overview

Frontend Load Balancing

Distribute incoming player connections across multiple Gate instances for horizontal scaling and high availability. The simplest approach uses Gate Connect’s built-in load balancing:
config.yml (All instances)
Setup:
  1. Configure first Gate instance with Connect
  2. Copy the connect.json token file
  3. Deploy additional instances with the same endpoint name and token
Benefits:
  • Zero configuration load balancing
  • Automatic health checks
  • Built-in failover
  • No additional infrastructure required
Use Cases:
  • 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
Key Configuration:
  • sessionAffinity: ClientIP - Ensures players reconnect to same instance
  • replicas: 3 - Run three Gate instances
  • Resource limits prevent resource starvation
Benefits:
  • 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.cfg
Configuration Highlights:
  • leastconn - Routes to instance with fewest connections
  • stick-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.
Use Cases:
  • Primary/backup server configurations
  • Failover without load distribution
  • Cost optimization (keep backup servers idle)
Behavior:

2. Random

Behavior: Randomly selects a backend for each new connection.
Use Cases:
  • Simple load distribution
  • Stateless server pools
  • Equal-capacity servers
Characteristics:
  • 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.
Use Cases:
  • Evenly matched server capacity
  • Predictable load distribution
  • Multiple identical server instances
Behavior:
State Management:
  • 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.
Use Cases:
  • Variable connection durations
  • Mixed server capacities
  • Optimal resource utilization
How It Works:
  • Tracks active connections per backend
  • Increments counter when connection established
  • Decrements when connection closes
  • Selects backend with minimum count
Example Scenario:

5. Lowest-Latency

Behavior: Routes to the backend with the fastest response time.
Use Cases:
  • Geographically distributed backends
  • Performance-critical routing
  • Heterogeneous server hardware
How It Works:
  • Measures ping/status response time
  • Caches latency data (3-minute TTL)
  • Selects backend with lowest recorded latency
  • Unknown latencies are measured first
Latency Tracking:

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:
Benefits:
  • Professional appearance during maintenance
  • Custom messaging for players
  • Prevents generic “connection refused” errors

Dynamic Backend Substitution

Use hostname parameters in backend addresses:
Example Routing:
Use Cases:
  • Kubernetes service discovery
  • Dynamic server pools
  • DNS-based routing

Caching and Performance

Optimize performance with ping caching:
Configuration:
  • cachePingTTL: 60s - Cache for 60 seconds (reduces backend load)
  • cachePingTTL: -1 - Disable caching (always ping backends)
  • cachePingTTL: 0 or omitted - Use default (10 seconds)
Benefits:
  • 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 the try list and forcedHosts:
config.yml
Behavior:
  • Players connecting via lobby.example.com try lobby1 first, fallback to lobby2
  • 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:
Logs will include latency measurements and selection reasoning.

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

Possible Causes:
  • Frontend load balancer not using sticky sessions
  • Long-lived connections (older connections remain on one server)
  • Backend capacity differences
Solutions:
  • Use least-connections strategy instead of round-robin
  • Configure session affinity on frontend load balancer
  • Ensure backends have similar capacity
Possible Causes:
  • Backend went offline after selection
  • Health check caching issues
Solutions:
  • Gate automatically tries next backend in list
  • Configure fallback status response
  • Reduce cachePingTTL for faster failure detection
Possible Causes:
  • Latency cache expired or not populated
  • Network conditions changed
  • Backends have similar latencies
Solutions:
  • Enable debug logging to see latency values
  • Verify backends are responding to status requests
  • Consider least-connections if latencies are similar

Performance Tuning

Connection Timeouts

Adjust timeouts for backend connections:
config.yml
Recommendations:
  • Lower connectionTimeout for faster failover (2-5 seconds)
  • Higher readTimeout for Forge/modded servers (30-60 seconds)

Resource Limits

Set appropriate resource limits for Gate instances:
kubernetes
Guidelines:
  • 512Mi-1Gi memory for small servers (< 100 players)
  • 1Gi-2Gi memory for medium servers (100-500 players)
  • 2Gi+ memory for large servers (500+ players)

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