Load Balancing Fundamentals Series

⚖️ Understanding Load Balancing Algorithms and Health Checks From a Top 1% Perspective — Why Round Robin Alone Isn't Enough

Introduction

This article is part of the Top 1% Series Complete Article Guide, and the second article in the Load Balancing Fundamentals Series.

Prerequisite Knowledge

Getting the Big Picture

The logic a load balancer uses to decide “which backend server gets the next request” is called a load balancing algorithm. And the mechanism that decides whether a server is even eligible to be a routing candidate in the first place is called a health check. These are two separate mechanisms, with two separate jobs.

graph TB
    Request["A New Request"] --> Algorithm["Load Balancing Algorithm<br/>(which server gets it)"]
    Algorithm --> HealthyPool["The Pool of Healthy Servers<br/>(maintained by health checks)"]
    HealthCheck["Health Check<br/>(periodic liveness check)"] --> HealthyPool

Deep Dive Into the Fundamentals

Load Balancing Algorithms: What Criteria Decide the Routing

AlgorithmRouting CriteriaGood Fit For
Round RobinDistributes evenly, in sequenceWhen every request’s processing time is roughly uniform
Weighted Round RobinDistributes by a ratio set per serverServers with different performance levels (send more to the stronger server)
Least ConnectionsSends to whichever server currently has the fewest active connectionsWhen per-request processing time varies
IP Hash (Source Hash)Hashes the client’s source IP address and always routes to the same serverWhen you need to pin a given client to a fixed server (session persistence, covered below)

Why isn’t round robin enough on its own? Round robin is the simplest possible scheme, assuming every request takes roughly the same amount of time to process. But if one request takes a long time (say, a large file upload), the server that received it holds that connection open longer than the others. Round robin mechanically keeps sending new requests to the same server anyway, purely because “it’s next in the rotation,” creating an imbalance where one specific server gets overloaded. The least-connections algorithm instead makes its decision dynamically, based on the load actually being processed right now, which is why it’s often preferred over round robin in real-world practice, for workloads with varying processing times.

Session Persistence (Sticky Sessions): Why You’d Ever Need to Pin to the Same Server

If a web application keeps session information, like login state, in a server’s own memory, then a given client’s requests getting routed to a different backend server each time produces a maddening symptom: the login that just succeeded appears to vanish the instant the request lands on a different server. To prevent this, the mechanism that always routes a given client’s requests to the same backend server is called session persistence (sticky sessions).

Doesn't Session Persistence Contradict the Whole Point of Load Balancing?

Session persistence, by pinning a specific client to a specific server, trades off against load balancing’s own goal of distributing load evenly, to some degree. Ideally, you’d externalize session information into a shared store (Redis, for instance) on the backend side, making the backend “stateless” — any server produces the same result — which eliminates the need for session persistence entirely. It’s best to understand session persistence as a practical compromise for when the backend can’t be made stateless.

Health Checks: How an Unhealthy Server Gets Detected and Removed

Health checks broadly come in two forms.

Active health checks are usually configured with the following parameters, to prevent flapping (the status rapidly flipping back and forth between healthy and unhealthy).

ParameterMeaning
IntervalHow often the health check runs
TimeoutThe maximum time to wait for a response on a single check
Fall thresholdHow many consecutive failures before marking the server “unhealthy”
Rise thresholdHow many consecutive successes before marking the server “healthy” again

Setting the fall threshold to 1 (marking a server unhealthy after a single failure) means a server gets needlessly pulled out of rotation over a brief network hiccup. On the other hand, setting the threshold too high means a genuinely failing server keeps receiving traffic for a while. Understanding this trade-off is essential to picking values appropriate to your service’s actual characteristics.

What a Pro Sees Here (Top 1% Understanding)

Algorithms and Health Checks Are Problems at Two Separate Layers

A common beginner mix-up is conflating “the routing algorithm” with “the health check.” A health check decides which set of servers is even eligible to be a routing candidate in the first place; the algorithm decides which server, from within that set, gets picked. Without keeping these two layers separate, you end up investigating in the wrong place — fixing the health check configuration, say, when a skew toward one specific server was actually caused by the algorithm’s own settings all along.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. One specific backend server is overloaded: Check the routing algorithm’s configuration (round robin vs. least connections) and the weighting settings.
  2. Login state keeps dropping unexpectedly: Check whether session persistence (sticky sessions) is configured, and whether it uses the cookie or IP-hash method.
  3. Traffic is still being sent to a server that’s already down: Check the health check’s fall threshold and interval settings, and whether detection is taking too long.

Summary

Takeaways to Apply Today

  1. When investigating a load imbalance, treat the algorithm’s configuration and the health check’s configuration as two separate problems to isolate.
  2. Before configuring session persistence, first consider whether the backend can be made stateless instead.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).