views:

31

answers:

2

Hello everybody,

I'm working on distributed web application and we decided to separate web module from business services to make it more scalable.

Here is the situation: We have one server instance that keeps web application (Controllers, JSPs, etc) and lots of server instances with business services. If web application needs any data it asks any of the existing business server via Hessian about it, then got the response and displays data.

Currently we retrieving data from DB based on logged in user and this cannot be changed, so every server should know which user asked to do the job.

My question is: Do you know the solution to keep user session across several independent applications?

For example one of the solutions can be send username with every request but this is not a very good idea for us.

Thanks a lot

A: 

There are 2 approaches for this problem:

1) Store all session info in central memcached server

2) Use session-aware load-balancer, which will direct same users to same nodes.

BarsMonster
+1  A: 

Use distributed hashtable to store and retrieve your sessions from any server. Try Hazelcast for example. It is open source and super simple; see the sample below.

Map<String, Session> mapSessions  = Hazelcast.getMap("sessions");
// session is created or updated so put it into the sessions map
mapSessions.put(sessionId, session);
// any server needing to access a session should just retrieve
// it from the map. 
// Map is distributed/shared so any JVM running Hazelcast can
// read the sessions.
Session session = mapSessions.get(sessionId);

Hazelcast is peer-to-peer. Just include a single jar and start sharing your sessions.

Talip Ozturk