Lavalink Infrastructure
Load Balancing & Clustering
How the Lavalink Gateway distributes player sessions across nodes to optimize audio fidelity and resource consumption.
When a Discord bot manages thousands of concurrent voice connections, hosting all players on a single machine leads to thread contention, GC pauses, and UDP packet drops. The Lavalink Gateway distributes player workloads across a dynamic cluster of nodes.
Load Balancing Topology
Discord Music Bot (Client)
│
WebSocket Handshake (WSS)
▼
Lavalink Gateway
│
┌────────────────────────┼────────────────────────┐
│ (Weight: 35%) │ (Weight: 40%) │ (Weight: 25%)
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Lavalink A │ │ Lavalink B │ │ Lavalink C │
│ (SG Region) │ │ (SG Region) │ │ (EU Region) │
├──────────────┤ ├──────────────┤ ├──────────────┤
│ 350 Players │ │ 400 Players │ │ 250 Players │
│ CPU: 32% │ │ CPU: 38% │ │ CPU: 24% │
└──────────────┘ └──────────────┘ └──────────────┘Selection Heuristics
The Gateway evaluates multiple real-time node telemetry metrics before routing a new player creation request (PLAYER_CREATE / voiceStateUpdate):
- Active Player Count: Avoids overloading individual nodes past their configured soft limits.
- CPU & System Load: Prioritizes nodes with lower instantaneous CPU utilization to ensure consistent audio frame delivery.
- Deficit Frame Rates: Nodes experiencing frame deficits or high jitter are temporarily deprioritized until metrics normalize.
- Geographic Proximity: Where possible, players in Southeast Asian voice servers are pinned to low-latency Singapore nodes (e.g.,
<2msRTT to Discord voice servers).
Node Scaling
Because all load distribution logic is handled centrally by the Gateway:
- New nodes can be provisioned and registered in seconds without reloading client bots.
- Low-traffic periods can trigger automated node scale-down to optimize cloud hosting costs.