Hi,

On Mon, Jun 16, 2025 at 12:52:45PM +0000, Boehm, Tamara wrote:
> It's interesting to learn that round-robin is considered a non-deterministic
> algorithm. We assumed it was deterministic because of its definition that
> requests are sent to the next backend/server one after the other. During our
> experiments with HAProxy 2.8.14, we could observe that this option has an
> impact on the load balancing.

Just for clarification, it's non-deterministic because you have no way
to guess where your request is going when you send it. The fact that a
previous similar request went to server 2 doesn't imply that the next
one would go there at all, and similarly, the same request sent to two
distinct load balancers having the exact same config and server state
will randomly reach a different server. So it varies with time and
space.

On the opposite, a hash-based algorithm will always route the request
to the same server as long as the same hashing key is presented. If for
example you hash the URI (which many cache-facing LBs do), you can send
the same request multiple times, through different LBs etc, it will
always reach the same server, and as such the algorithm is considered
as deterministic.

As such, "balance roundrobin", "balance random", "balance leastconn",
"balance first" are non-deterministic. "balance hdr()", "balance source",
"balance uri", "balance url_param", "balance rdp-cookie", "balance hash"
with an expression extracted from the client's connection or request,
are deterministic.

The difference is important for retries and saturated servers: when a
connection cannot be established to a server, if the LB algo is non-
deterministic, haproxy can try to find another server. If it is
deterministic, it will not try to find another server.

Hoping this helps,
Willy


Reply via email to