HAProxy Enterprise Documentation 2.0r1

Session Persistence

Session persistence means that HAProxy Enterprise routes a client to the same backend server once they have been routed to that server once. It avoids the overhead of re-establishing a client's state on a new server with each request, since the same server is always chosen. Often, it is optimal to avoid session persistence altogether by building your services to be stateless, such as by storing state off of the application servers in a shared database. However, for certain applications this is not possible.

HAProxy Enterprise supports two forms of session persistence:

  • Persistence based on an HTTP cookie. This option is only available with mode http.

  • Persistence based on the client's IP address. This option is available with mode http and mode tcp.

IP-based persistence

To enable session persistence based on the client's IP address:

  • Add a stick-table line to your backend section. It creates an in-memory storage to hold client IP addresses. Entries in the stick table expire after 30 minutes if they are not used.

  • Add the line stick on src, which stores a client's IP address in the stick table and associate it with the server to which they were routed. On subsequent visits, they will use this same server.

backend servers
   mode tcp
   stick-table type ip  size 1m  expire 30m
   stick on src
   server s1 192.168.0.10:80 check
   server s2 192.168.0.11:80 check

Next up

Traffic Routing