Is Memcache recommended when using MongoDB?

Daniel Vigueras picture Daniel Vigueras · Nov 25, 2010 · Viewed 19.1k times · Source

I would like to know if Memcache is recommended when using a NoSQL database like mongoDB.

Answer

Gates VP picture Gates VP · Nov 25, 2010

The concept of using memcache stems from the idea that you have "extra RAM" sitting around somewhere. Both MongoDB and MySQL (and most DBs) will take every meg of RAM that they can get.

In the case of the very common MySQL / Memcache, it is very well documented that using Memcache is more about reducing query load on the server than it is about speeding up queries. A good memcache implementation basically just tries to keep the most common data in memory so that the database server can churn away on bigger stuff.

In fact, it's been my experience that use of memcache generally becomes a reliance on memcache to maintain system performance.

So back to the original question, where do you have extra RAM?

If you have extra RAM on web servers, you may be able to use Memcache. Of course, you could also run Mongo locally on the web server. Just slave the data you need from the master.

If you have extra RAM on other computers, then there's not really a point in using memcache. Just add more nodes to your MongoDB replica set or shard. This is where MongoDB actually shines. Because of sharding / replication, you can add more RAM to Mongo Horizontally to increase performance. With SQL it's very difficult to "just add more servers" because joins don't scale very well. But with Mongo, it's quite possible to simply "add more nodes" to a problem.