Session management in a distributed application

I am working on a distributed web application, and we decided to separate the web module from the business services to make it more scalable.

Here is the situation: We have one server instance that stores the web application (controllers, JSP, etc.) And many server instances with business services. If the web application needs any data, it queries any existing business server through Hessian, then receives a response and displays the data.

We are currently retrieving data from the database based on the registered user, and this cannot be changed, so each server must know which user asked to complete the task.

My question is: Do you know a solution to save a user session in several independent applications?

For example, one of the solutions may send a username with each request, but this is not a good idea for us.

Thank you so much

+5
source share
2 answers

Use a distributed hash table to store and retrieve sessions from any server. Try Hazelcast , for example. It is open source and super simple; see 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 a peer to peer. Just turn on one jar and start sharing your sessions.

+4
source

There are 2 approaches to this problem:

1) Save all session information on the memcached central server.

2) , , .

+2

All Articles