# Sticky TCP load balancing

**URL:** <https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287>\
**Category:** Help!\
**Created:** [June 5, 2017, 6:53am UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287 "2017-06-05T06:53:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnkitSinghai](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@AnkitSinghai](https://discourse.haproxy.org/u/AnkitSinghai)\
**Post date:** [June 5, 2017, 6:53am UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/1 "2017-06-05T06:53:20Z")

</div>

I have to load balance incoming TCP connections but the source is same for all (i.e they all are coming by a gateway), please suggest alternate options that can be used.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [June 5, 2017, 11:24am UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/2 "2017-06-05T11:24:48Z")

</div>

Literally every other load-balancing option expect source-ip stickiness.

In TCP mode, the backend session will be connected end-to-end to the frontend, so no actual stickiness should be required, in any case, it isn’t possible to achieve stickiness beyond the TCP session, when source-IP is out of question, because we cannot set cookies or learn application session IDs in a stick-table when in TCP mode.

---

<div class="post-metadata">

**Author:** ![AnkitSinghai](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@AnkitSinghai](https://discourse.haproxy.org/u/AnkitSinghai)\
**Post date:** [June 5, 2017, 11:47am UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/3 "2017-06-05T11:47:17Z")

</div>

Thanks Lukas for your advice, can we use send-proxy and accept-proxy to achieve stickiness beyond TCP session liveliness in TCP mode ? can LUA programming would be of any help?

Thanks in Advance  
Ankit Singhai

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [June 5, 2017, 3:47pm UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/4 "2017-06-05T15:47:26Z")

</div>

No (the proxy protocol has nothing to do with it) and unlikely (but I am not a LUA expert, and it depends what the protocol looks like).

What is the protocol you are load-balancing and why do you believe you need stickiness beyond the TCP session?

---

<div class="post-metadata">

**Author:** ![AnkitSinghai](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@AnkitSinghai](https://discourse.haproxy.org/u/AnkitSinghai)\
**Post date:** [June 7, 2017, 5:33am UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/5 "2017-06-07T05:33:00Z")

</div>

On backend servers we are using local caching to store the user-related information that’s why we want to calls to be sticky on server to avoid again fetching data from distributed caching server.We are using Netty 4.X to make TCP calls to HAProxy.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [June 7, 2017, 12:07pm UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/6 "2017-06-07T12:07:16Z")

</div>

You need to switch to HTTP as protocol and “mode http” in haproxy. Otherwise you cannot achieve stickiness.

---

<div class="post-metadata">

**Author:** ![AnkitSinghai](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@AnkitSinghai](https://discourse.haproxy.org/u/AnkitSinghai)\
**Post date:** [June 7, 2017, 12:18pm UTC](https://discourse.haproxy.org/t/sticky-tcp-load-balancing/1287/7 "2017-06-07T12:18:43Z")

</div>

Thanks Lukas for your suggestion
