Skip to content

Balance Algorithms

The ten balance algorithms the Dataplane v3 API accepts, their argument fields, and the hash-type requirement that causes most apply failures.

The Dataplane v3 API accepts exactly ten balance algorithms. HAProxy UI exposes all ten in the backend inspector, and exposes the argument fields for the six that take arguments.

Algorithms

Algorithm Arguments Inspector fields Emitted as
roundrobin none — balance roundrobin
static-rr none — balance static-rr
leastconn none — balance leastconn
first none — balance first
source none — balance source
hash required Hash sample expression balance hash req.uri
uri optional Hash whole URI (toggle), URI length, URI depth balance uri whole len 5
hdr required Header name balance hdr(host)
url_param required Parameter name, Check on POST, Max wait (ms) balance url_param user_id check_post 1 max_wait 5
rdp-cookie required Cookie name balance rdp-cookie sessid
random optional Draws balance random draws 4

Algorithms not in this list — alpha, cookie, map(<file>) — are not part of the v3 schema and are rejected by the API. They are deliberately absent from the dropdown rather than offered and then refused.

Hash type

When the algorithm is hash or uri, haproxy requires the backend to also declare a hash-type. Without it the apply is rejected with “balance hash requires a sample expression”-class errors.

The dropdown offers the seven values the v3 spec enumerates across hash_type.method, .function and .modifier:

Value Spec slot Notes
map-based method The haproxy default
consistent method Minimal remapping when servers join or leave — the usual choice for stickiness
avalanche modifier Defends the hash map against chosen-key attacks
crc32, djb2, sdbm, wt6 function Hash function selection

How hash-type is stored. The v3 spec models it as an object ({method, function, modifier}). HAProxy UI keeps the whole directive as a string instead. This is deliberate: the string form round-trips byte-stable through the parser and serializer, and the API accepts it. Splitting it into three fields would add a shape conversion that changes nothing a user can act on. Upgrade this only if the Dataplane ever rejects the string form.

How the fields behave

  • Fields appear on demand. Each argument field is hidden unless its algorithm is selected, so the backend inspector shows only the arguments that are meaningful for the current choice.

  • Clearing a field removes the argument. Emptying the header name on a hdr backend drops hdr_name and the backend reverts to the bare balance hdr form — which haproxy will reject, deliberately, rather than silently invent a header.

  • Switching algorithm keeps other arguments. Changing from uri to hash preserves uri_whole in the model until it is explicitly cleared. This is intentional: the arguments are keyed independently of the algorithm, and dropping them silently on a dropdown change would lose work.

Troubleshooting

“balance hash requires a sample expression” — the hash expression field was left empty. Fill it in (for example req.uri).

“backend requires a hash-type” — set the hash type as well. Both fields are required together.

Apply succeeds but the config does not look right — check the raw-payload panel for a balance line carried verbatim from a paste-import; an unparsed directive will take precedence over the modelled one.