Skip to content
Veltoryx Technologies
ProLesson 2.3Intermediate10 min readUpdated 31 October 2026

Load Balancing Algorithms and Consistent Hashing

Distributing client requests across server pools: round robin, least connections, weighted distribution, and consistent hashing rings with virtual nodes.

Once a load balancer receives an incoming connection, it must answer a crucial algorithmic question: which exact server in the backend pool should process this request?

Picking the right load balancing algorithm dictates how smoothly your system performs under peak traffic. An algorithm that works well for lightweight stateless REST requests can cause severe server lockups if used for long-lived database connections or stateful caching tiers.

Consistent Hashing Ring and Virtual Nodes
Fig. 1 · Consistent Hashing Ring and Virtual Nodes

01Traditional Load Balancing Algorithms

Load balancing algorithms divide into two broad categories: static algorithms (which make routing choices without inspecting real-time server health metrics) and dynamic algorithms (which continuously monitor active server load).

Static Algorithms

Round Robin

The simplest algorithm available. The load balancer maintains an ordered list of backend servers and routes incoming requests sequentially: Request 1 goes to Server A, Request 2 goes to Server B, Request 3 goes to Server C, and Request 4 loops back to Server A.

  • Best for: Homogeneous server fleets where all machines have identical hardware specs and every request consumes approximately the same amount of CPU processing time.
  • Failure Mode: If Server A receives three heavy database-export queries in a row while Server B receives three lightweight health checks, Server A's CPU spikes to 100 percent while Server B sits idle. Round robin is blind to active connection count.

Weighted Round Robin

Extends standard round robin by assigning an integer weight to each server based on its physical capacity:

  • Server A (8 cores, 32GB RAM): Weight = 2
  • Server B (16 cores, 64GB RAM): Weight = 4
  • The load balancer routes 2 requests to Server A for every 4 requests sent to Server B.
  • Best for: Heterogeneous fleets where legacy servers operate alongside modern, higher-spec instances.

IP Hash (Source IP Affinity)

Computes a hash of the client's source IP address and maps it to a server index:

text
server_index = hash(client_ip) % N
  • Best for: Basic session persistence when application servers hold state locally and a centralized cache (like Redis) is not yet available.
  • Failure Mode: If thousands of corporate users connect through a single corporate NAT proxy or mobile gateway, they all share the exact same public source IP. Every request gets routed to the same single server, overwhelming it while others sit unused.

Dynamic Algorithms

Least Connections

The load balancer tracks the number of open, active concurrent connections on every server in real time. Incoming requests are always dispatched to whichever server currently holds the fewest active connections.

  • Best for: Transactions with highly variable execution times, such as SQL database query pools, video streaming connections, or long-polling WebSocket chats.

Weighted Least Connections

Combines real-time connection tracking with server capacity weights. A server with twice the capacity rating is expected to handle twice the active connections before being considered busier than a smaller server.

Least Response Time (Latency-Based)

The load balancer combines the number of active connections with the average response latency of each server (often determined by periodic health check probes). It routes requests to the server that answers fastest.

  • Best for: Multi-datacenter setups where network variance or noisy neighbor virtualization can slow down individual nodes unpredictably.

Loading the rest of the lesson…