node.js - Redis and MongoDB; How should I store large JSON objects, Performance issue -
i developing node.js app. has mysql database server use store of data in app. however, find myself storing lot of data pertains user in session storage. how have been doing using express-session store contents of user class these user classes can quite large. thinking writing middleware save user class json either redis or mongodb , store key storage within session cookie. when retrieve json redis or mongodb, parse , use reconstruct user class.
my question method fastest performing , scalable: storing json strings in redis, or storing mongo document representation of user class in mongodb? thanks!
edit: planning include mongodb in part of app, solving different issue. json parsing redis more time-consuming , memory intensive parsing mongo? @ reoccuring user count server memory sessions become problem?
express-session
has various session store options save session data to.
afaik, these work through same principle: serialize session object json string, , store string in store (using session id key).
in other words, idea of storing user data json string in either redis or mongodb using second key same express-session
when using redis or mongodb stores. wouldn't expect performance benefits that.
another option store user data proper mongodb document (not serialized json string). under hood still require (de)serialization, although , bson, not json. have never benchmarked of 2 faster, i'm gonna guess , json might tad quicker.
there's difference between redis , mongodb, in redis in-memory , more lightweight. however, mongodb more of "real" database allows more elaborate queries , has more options in terms of scalability.
since seems me you're storing transient data in sessions (as actual data stored on mysql), suggest following:
- use redis session store if total amount of data you're storing in sessions fit in memory;
- use mongodb session store if not.
Comments
Post a Comment