Haproxy deterministic persistence cookie

i have two servers that i want to balance. i want to use a consistent hashing method to balance them accross both servers. if one server goes down i want all customers on this server to fail over to the other, but i also want them to return once the server comes back online. this happens often enough that a stick table would just cause all the traffic to be sent to the other server for rest of the day.

The second part of this is that we need each customer to be on the same server. so customer 1 would have 5 users and they should be using the same backend server. as you can probably tell we don’t have a stateless design and there are some state issues that require this.

below is my ideal config. but obviously doesn’t work. my idea was to set a cookie from the web app per customer and have that be hashed so as to indicate which server they log into.

backend servers
    hash-type consistent sdbm
    balance req.cook(server_indicator)
    server s8000 127.0.0.1:8000 check
    server s8001 127.0.0.1:8001 check

looks like i found a solution. not sure this is the best solution but it does appear to work correctly

listen add_header
    mode http
    bind *:10080
    http-request add-header X-SRV-IND %[req.cook(srv_ind)]
    server me 127.0.0.1:10081

frontend test_header_stuff
    mode http
    bind *:10081
    default_backend servers

backend servers
    mode http
    hash-type consistent sdbm
    balance hdr(X-SRV-IND)
    server s8000 127.0.0.1:8000 check
    server s8001 127.0.0.1:8001 check
    server s8002 127.0.0.1:8002 check
    server s8003 127.0.0.1:8003 check