14

I am working on a project, where each user can post many images. We use Node.js with Express and MongoDB as the database. I was wondering which way would be better in terms of speed and scalability:

  • Storing images in Mongo GridFS

Or

  • Storing images on Amazon S3, and paths of images on MongoDB. Then retrieve images using paths.

Any thoughts are appreciated !

Thank you,

Community
  • 1
  • 1
c0mrade
  • 1,360
  • 3
  • 14
  • 24
  • I dunno, have you tried it? – SomeKittens May 25 '14 at 04:59
  • 9
    What a stupid close reason. This question does not have an answer that is "primarily opinion-based". Too broad maybe, but bad reason guys. When will SO have a way to counter act stupid triggerhappy closures like this that leave only one answer the undisputed champion. Either delete it or leave it open. – B T Aug 11 '16 at 22:38

1 Answers1

21

This is like comparing Go vs Node.js. There's no better general solution.

Each might have their own advantages and solutions. MongoDB is more like the DIY solution, and Amazon S3 is the managed solution. With MongoDB you have to scale it yourself. I can say S3 will be faster initially and it's already scaled by Amazon, and probably cheaper(S3 is cheaper than EBS). You can get a lot of servers with huge amounts of RAM and MongoDB will definitely be faster. Also if the MongoDB instance is in the same instance as your App, you will have less latency.

Also check this question: MongoDB as static files provider?

And this: What are the advantage of using MongoDB GridFS vs Amazon S3 to store assets for a product with MongoDB as the database backend?

Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115
  • Thanks Farid for the quora link ! it is very helpful ! – c0mrade May 25 '14 at 22:24
  • Hi Farid. I could not understand why you said "huge amounts of RAM"? AFAIK MongoDB will stream files while reading/creating them, And it will be super light from RAM point of view. Right? – Kasir Barati Sep 20 '22 at 08:28
  • 1
    @KasirBarati S3 would likely serve the files from disks, which is slower compared to serving the file directly from RAM. MongoDB and also operating system filesystem would cache the data. More RAM, means more caching, leading to lower latency and higher throughput. – Farid Nouri Neshat Sep 20 '22 at 09:53
  • Aha, I got your point @FaridNouriNeshat. https://www.mongodb.com/docs/manual/faq/fundamentals/#does-mongodb-handle-caching- – Kasir Barati Sep 20 '22 at 09:57