0

Assuming a cluster of webservers on EC2 with both Elastic Load Balancing and Auto Loading (meaning instances start and die based on demand), can someone tell me what happens to a user's browser's session? Is the load balancer smart enough to track sessions? Or at least smart enough to send a particular user's requests to the same instance consistently? Or do I have to find and manage a solution to this problem myself?

Caleb
  • 11,813
  • 4
  • 36
  • 49

3 Answers3

2

Need more information, it depends on how you are implementing your sessions. Although some load balancers are 'smart' enough to redirect based on sessions, relying on that really just means your architecture is broken in the first place.

Ideally you want either a centralized or distributed session store. Good options are a centralized database like MySQL, or something distributed like memcached. You probably want to start with the database, and move to memcached if you really start gaining traffic.

What framework or language is your application using?

anveo
  • 141
  • 3
  • The platform is JBoss with MySQL. JBoss supports clustering through multicast (not supported on EC2). Putting the session in the database is an option. Another possible option is having the JBoss instances cluster through the use of a 'gossip' server. My question is to what degree can I rely on EC2 for session handling. –  Aug 17 '09 at 02:02
  • Your framework should be handling the session, not EC2. Configure JBoss to store the session in the database, and you will have no worries :) – anveo Aug 17 '09 at 20:40
1

No, ELB is not a sticky session based load balancer. It is a 'not strict round robin' based load balancer that does not take into account your session scheme. Some details are investigated here: http://clouddevelopertips.blogspot.com/2009/07/elastic-in-elastic-load-balancing-elb.html

If you want to use elb then you need to make sure your session scheme can deal with the requests being routed to any of the servers in the elb pool at any request.

dar
  • 509
  • 1
  • 5
  • 11
0

You have two options.

Your best option is to do as anveo said. Using a centralized session store means that they can hit any one of your servers and still have their session. You can spin up and terminate instances without worrying about the effect on the users.

Another option is the use the stickiness option of the ELB. You can create session cookies and the load balancer will route a session cookie to the same instance each time. The problem with this is that you can not freely kill instances because people will lose their sessions (if that matters). The only upside to this method is that it is extremely simple to implement. And losing sessions isn't that bad normally. The user would just log back in again.

Stephen
  • 345
  • 1
  • 7