# Consistent hashing and stick tables

**URL:** <https://discourse.haproxy.org/t/consistent-hashing-and-stick-tables/9623>\
**Category:** Help!\
**Created:** [March 14, 2024, 2:16am UTC](https://discourse.haproxy.org/t/consistent-hashing-and-stick-tables/9623 "2024-03-14T02:16:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dayoff](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/dayoff/32/2187_2.png) [@dayoff](https://discourse.haproxy.org/u/dayoff)\
**Post date:** [March 14, 2024, 2:16am UTC](https://discourse.haproxy.org/t/consistent-hashing-and-stick-tables/9623/1 "2024-03-14T02:16:55Z")

</div>

Is it possible to use bounded-load consistent hashing with stick tables?

I have a case where I want to use bounded-load consistent hashing and I want to have consistency across multiple haproxy nodes. I’m using a DNS resolver to generate my servers by using the **server-template** , but my DNS resolver returns the IPs in a round-robin order, which causes inconsistency across the haproxy nodes. Example:

haproxy 1:  
svr1 → 10.2.174.177  
svr2 → 10.2.174.178

haproxy 2:  
svr1 → 10.2.174.178  
svr2 → 10.2.174.177

Therefore, I wonder if by using **stick-tables** with **srvkey addr** (to map my balance key with the server address instead of the server name) would it work? How the **hash-balance-factor** generates the relation between balance key and server reference?

This is my backend haproxy config:

```auto
    backend back
      mode http

      balance url_param id
      hash-type consistent
      hash-balance-factor 150

      stick-table type string size 1m srvkey addr

      stick store-request url_param(id) table back
      stick on url_param(id) table back

      server-template svr 5 hostname:5000 check inter 2s fall 3 rise 2 resolvers k8s init-addr none

```

---

<div class="post-metadata">

**Author:** ![adarragon](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@adarragon](https://discourse.haproxy.org/u/adarragon)\
**Post date:** [June 25, 2024, 8:38pm UTC](https://discourse.haproxy.org/t/consistent-hashing-and-stick-tables/9623/2 "2024-06-25T20:38:49Z")

</div>

Since 3.0 there is `hash-key` directive which was added for that purpose:  
[https://docs.haproxy.org/3.0/configuration.html#5.2-hash-key](https://docs.haproxy.org/3.0/configuration.html#5.2-hash-key)

See also:  
[https://www.mail-archive.com/haproxy@formilux.org/msg44607.html](https://www.mail-archive.com/haproxy@formilux.org/msg44607.html)
