Saturday, February 27, 2016

AWS Elastic Load Balancing session stickiness - Part 2

In my previous post "AWS Elastic Load Balancing session stickiness" I demonstrated the use of AWS ELB  Load Balancer Generated Cookie Stickiness. In this post we'll use application generated cookie to control session stickiness.
To demonstrate this feature, I created a simple ASP.NET MVC application that just displays some instance details to test the load balancing.

Starting from the default ASP.NET MVC web application template, I modified the Index action of the HomeController:

Similar to what I've done in the previous posts using Linux shell scripts, this time I'm using C# code to request instance metadata from the URL then I store the host name and IP address in the ViewBag object and display them in the view:

I deployed the application to two EC2 Windows 2012 R2 instances. As expected, using the default ELB settings, requests will be routed randomly to one of the instances. This can be tested by looking at the host name and IP displayed in the response.

Looking to the request and response cookies, we can find the session cookie added:

To configure stickiness based on the ASP.NET_SessionId cookie, edit the stickiness configuration and enter the cookie name:

Checking the cookies, we find that ELB generates a cookie named "AWSELB". As documented: "The load balancer only inserts a new stickiness cookie if the application response includes a new application cookie."

Now the browser will send back both the session and ELB cookies:

Still my preference for maintaining session state is to use a distributed cache service like Redis or even SQL server. Because in case an instance goes down or is removed from an auto-scaling the user will lose his session data in case it's stored in memory.


Tanishka said...

Really an awesome post. I wondered by reading this blog post. Thanks a lot for posting this unique post which you have shared with us. Keep on posting like this exclusive post with us.

Hadoop Training in Chennai

Anu Sri said...

Excellent post !. I learned lot of information. Thanks!

php training in chennai

Arjun Rishi said...

Great article. Thanks for sharing such a useful post.

ppc training in chennai

Anu Sri said...

Nice post. glad to find your blog. Thanks for sharing.

web design training institute in Chennai

Andrew Son said...

Hadoop is a framework which has four classifications in it. Each has different properties and apache hadoop is an open source software framework. It is used for distributed processing and distributed storage. It use handle large set of data and information.
Big Data Training in Chennai | Hadoop Training in Chennai

Nivedageorge said...

Great article, Happy to visit your blog. Keep sharing such a useful post.

SEO Training in Kodambakkam

jhansi joe said...

Im no expert, but I believe you just made an excellent You certainly understand what youre speaking about, and I can truly get behind that.
SEO Training

Jhon Mick said...

Php is abbreviated as Hypertext preprocessor. Learn php and its dynamic working behavior is really interesting.
PHP Training in Chennai | PHP Course in Chennai

Anonymous said...

Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post. java training in jalandhar