Why Use Redis instead of MongoDb for Caching? [closed] Why Use Redis instead of MongoDb for Caching? [closed] mongodb mongodb

Why Use Redis instead of MongoDb for Caching? [closed]


A lot of people do use MongoDB for a low-medium grade cache and it works just great.

Because it offers more functionality than a simple key value store via ad-hoc queryability it isn't as pure of a caching layer as a memcache or redis (it can be slower to insert and retrieve data).

Extremely high performance is attainable (the working set is in RAM after all), but the data model is heavier.

However, on the flip side, MongoDB does offer a persistance layer that makes a lot more sense (to most developers) for the type of data that is most likely needed at a later time, unlike Redis.


The biggest difference between MongoDB and Redis is that Redis usually stores the entire database in memory. MongoDB uses a memory mapped file to pretend everything is in memory, and lets the OS page bits in and out of disk as necessary. If the OS can keep everything in memory, performance will be somewhat similar.


When we say caching, speed comes to mind. The goal here is to set and retrieve something as fast as possible. In this sense, redis is faster than mongodb. However, if you find that mongodb is suitable for doing geospatial searches on cached data, it's ok to use it. You can of course invest some time and implement the same in redis, and then benchmark to see what you gain.