Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

any benefit from using Hazelcast instead of MongoDB to store user sessions/keys?

We are running mongodb instance to store data in a collections, no problems with it and mongo is our main data storage.

Today, we are going to develop Oauth2 support for the product and have to store the user sessions (security key, access token and etc.. ) and the access token have to be validated against the authentication server only after the defined timeout so that not every request will wait for validation by authentication server. First request for secured resource (create) shall always be authenticated against the authentication server. Any subsequent request will be validated internally (cache) and check the internal timeout and only if expired, another request to the authentication server will be issued.

To solve that requirements, we have to introduce some kind of a distributed cache, to store (with TTL support) the user sessions and etc, expire it based on a ttl.. .i wrote about that above.

Two options here:

  1. store user session in the hazelcast and share it across all App servers - nice choice, to persists all user session in eviction map.
  2. store user sessions in MongoDb - and do the same.

Do you see any benefits of using Hazelcast instead of storing the temp data inside Mongo? Any significant performance improvements you're aware of ?

I'm new to Hazelcast, so don't aware about all killer features.

like image 808
IgorA Avatar asked Mar 18 '13 14:03

IgorA


2 Answers

Disclaimer: I am the founder of Hazelcast...

  1. Hazelcast is much simpler and simplicity matters a lot.
  2. You can embed Hazelcast into your application (if your application is written in Java). No need to deploy and maintain remote nosql cluster.
  3. Hazelcast works directly with your application objects. No JSON or any other format. Write and read java objects.
  4. You can execute Java code on your in-memory data. No need to fetch and process data; send your code over to the data.
  5. You can listen for the updates on your data. "Notify me when this map or key is updated".
  6. Hazelcast has rich set of data structures like queue, topic, semaphores, locks, multimap etc. Imagine sharing a queue across multiple nodes and be able to do blocking queue poll/take operation... this is really cool :)
like image 183
Talip Ozturk Avatar answered Oct 18 '22 23:10

Talip Ozturk


Hazelcast is an in-memory grid so it should be significantly faster than MongoDB for that kind of usage. They also have pre-made session clustering code for Java servlets if you do not want to create that yourself.

Code for the session clustering here on github. Or here for Maven artifact.

like image 27
Sten Roger Sandvik Avatar answered Oct 18 '22 22:10

Sten Roger Sandvik