AWS News Blog

New Elastic Load Balancing Feature: Sticky Sessions

Voiced by Polly

Amazon EC2’s Elastic Load Balancing feature just became a bit more powerful. Up until now each load balancer had the freedom to forward each incoming HTTP or TCP request to any of the EC2 instances under its purview. This resulted in a reasonably even load on each instance, but it also meant that each instance would have to retrieve, manipulate, and store session data for each request without any possible benefit from locality of reference.

Suppose two separate web browsers each request three separate web pages in turn. Each request can go to any of the EC2 instances behind the load balancer, like this:

When a particular request reaches a given EC2 instance, the instance must retrieve information about the user from state data that must be stored globally. There’s no opportunity for the instance to cache any data since the odds that several requests from the same user / browser will go down as more instances are added to the load balancer.

With the new sticky session feature, it is possible to instruct the load balancer to route repeated requests to the same EC2 instance whenever possible.

In this case, the instances can cache user data locally for better performance. A series of requests from the user will be routed to the same EC2 instance if possible. If the instance has been terminated or has failed a recent health check, the load balancer will route the request to another instance. Of course, in a real world scenario, there would be more than two users, and the third EC2 instance wouldn’t be sitting idle.

Full information on this new feature can be found in the Elastic Load Balancer documentation.

Update: Shlomo Swidler wrote a really nice post on Elastic Load Balancing with Sticky Sessions. I’d encourage you to check it out to learn more about why sticky sessions can improve your application.

— Jeff;