Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I store an image in MongoDB or in local File System (by Node.js)

I use Node.js for my project.

Should I store an image in local file system, or should I store it in MongoDB?

Which way is more scalable?

like image 315
murvinlai Avatar asked Jan 29 '12 02:01

murvinlai


2 Answers

The most scalable solution is to use a shared storage service such as Amazon's S3 (or craft your own).

This allows you to scale horizontally a lot easier when you decide to add machines to your application layer, as you won't have to worry about any migration nightmares.

The basic idea behind this is to keep the storage layer decoupled from the application layer. So using this idea you could create a node.js process on a separate machine that accepts file uploads then writes them to disk.

like image 132
Tim Smart Avatar answered Sep 28 '22 00:09

Tim Smart


If you're designing a performance sensitive system, use file system to store your images no doubt.

You can find the performance compare from this blog: http://blog.thisisfeifan.com/2013/12/mongodb-gridfs-performance-test.html

Actually, you can find the recommended MongoDB GridFS use cases here: https://docs.mongodb.com/manual/core/gridfs/#when-to-use-gridfs

like image 38
feifan.overflow Avatar answered Sep 28 '22 01:09

feifan.overflow