I need to load a few fields of information that changes infrequently for validation of routes that a user might access.
Currently, I query mongodb and store those fields in redis alongside any particular state information in a single hash that is keyed by 'user:' + mongodb_user_objectid
when a user logs in.
Then I create a session for the http cookie and store this key as a string in redis as well keyed by 'sess:' + session_id
.
Would it be better to not copy over the fields from mongodb and deal with updating both redis and mongodb when one of those validation fields may change?
Is there a significant performance difference from reading and writing this session information directly from/to mongodb without using redis as a middleman?
Redis handles large volumes of workload more comfortably as compared to MongoDB. Redis is single-threaded which means it runs on a single core. So, in terms of performance, Redis is slightly better than MongoDB. MongoDB is also known to respond slowly once it is bound by the CPU.
Redis Enterprise is a popular database ideal for both cache and session store use cases, delivering both the high-availability required for caching and session store scenarios as well as the durability needed for session store with in-memory replication.
MongoDB is schemaless, which means that the database does not have a fixed data structure. This means that as the data stored in the database gets larger and larger, MongoDB is able to operate much faster than Redis. Redis is only significantly faster when the stored data is relatively small in size.
Redis is often used in combination with an on-disk database such as MongoDB. While the on-disk database is the primary storage solution, Redis may be used as a caching layer, or for performing real-time analytics. If you're already using MongoDB, you can achieve similar results without adding Redis to your system.
Unfortunately, a definite answer will require a measurement using your setup because there are so many potential factors.
However, my guess is that the overhead of using two datastores outweighs any potential advantages because the reads should be incredibly fast on both DBs:
So, in a nutshell, I don't see any reasons why redis would be a lot faster in this case, but again, performance is often guesswork, especially when the details are unknown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With