Typically synonymous with "stickiness," persistent connections describe a state in which connections during a user's session are always sent to the same backend server. Load balancers and application delivery platforms can also maintain a longstanding virtual connection between clients and specified servers. This helps preserve routing behaviors while maintaining important state and session information. 

How do persistent connections work?

Persistence ensures that a given client's requests will hit the same server every time throughout the duration of their user session. Persistence relies on persistent connections or session cookies (usually set by the proxy)  to function properly. Here's a quick summary of how it works:

  • A request is routed through a load balancer, which then chooses a destination server for that request. 

  • Any new requests that the client makes reach the same destination server. 

  • Application delivery controllers leverage request data such as headers, TCP protocol information, and IP address details to uphold persistence. Cookies also play a pivotal role in supplying vital persistence information to intermediaries like load balancers. 

What makes persistent connections useful?

Handling a client's session with the same backend server ensures that the state (like session IDs) used by the backend to service the client won't get lost, while also balancing different clients across different servers to maximize performance. Here are some common benefits, some of which we've already touched on: 

  • Avoiding the need to reestablish state on the server

  • Performance gains through multiplexing, which includes both throughput gains and increased server capacity

  • Reduced network traffic and overutilization of concurrent connections

  • Avoiding the need for application rewrites to enable session persistence when moving to a load-balanced environment

By improving performance and overall efficiency, persistence paves the way for improved user experiences. 

You’ve mastered one topic, but why stop there?

Our blog delivers the expert insights, industry analysis, and helpful tips you need to build resilient, high-performance services.

By clicking "Get new posts first" above, you confirm your agreement for HAProxy to store and processes your personal data in accordance with its updated Privacy Policy, which we encourage you to review.

Thank you! Your submission was successful.

How does HAProxy handle persistent connections? 

Since HAProxy is a proxy-based load balancer, we support persistence across TCP/HTTP connections as one of our main application acceleration features. We support session persistence based on either HTTP cookies or client IP addresses. 

Setting up persistence in HAProxy is fairly straightforward. To learn more about the process, read our session persistence documentation