Persistence

From LB Wiki

Jump to: navigation, search

Persistence, sometimes referred to as affinity, is the mechanism whereby repeated client connections are sent to the same server. Normally a load balancer would distribute load according to the load balancing algorithm (round robin, least connections, etc.). A user coming would hit server 1 on their initial connection, server 2 on the second hit, server 3 on the third hit, and so on.

Some applications are stateful, in that information specific to the user's session is only stored on a single server. This is typically temporary information, such as login credentials, shopping carts, and other information that may not be stored on a back end database. Because of this, each individual user needs to be tied to a single server.

Source IP Address

The most basic method of persistence is source IP address. When a new connection comes in, the load balancer will send all subsequent connections that come from the same IP address to the same server.

It's typically the only option for non-HTTP protocols, such as FTP. It's also the only option for certain load balancers that only operate on Layer 4.

Cookie-based Persistence

With cookie-based persistence, the load balancer looks for an HTTP cookie in the client session. This cookie has a unique value per each user, and the load balancer will keep a user persistence based on that unique value.

There area several variations of cookie based persistence:

  • Active cookie: The load balancer inserts a new cookie into the session
  • Passive cookie: The load balancer uses a cookie that's already been generated

Generally, active cookie is the best option. It doesn't require you to change your application (as passive cookies would), and it doesn't interfere with any cookies your application may generate.

Process for Active Cookie Persistence

When any HTTP connection comes into the load balancer, it checks for a specific cookie. In this example, the cookie is named "lbpersist". If that cookie isn't in the session, it will insert the cookie:

Set-Cookie: lbpersist=B56C0C63-0FD3-4AD5-B5A9-4236BD97DA50

With each subsequent request, the client's browser will send this cookie:

Cookie: lbpersist=B56C0C63-0FD3-4AD5-B5A9-4236BD97DA50

Because cookies are so prevalent, the vast majority of users will accept them, so that's not an issue. And if it is, many load balancers offer a fall-back method: If cookies aren't accepted, the load balancer will revert to source IP address persistence.

Personal tools
Advertisements