Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Uploads - CDN, MongoDB, or NFS?

I have an admin type system for a website with multiple web servers where users can configure pages and upload images to appear on the page (kind of similar to a CMS). If you already have a MongoDB instance with replica sets setup, what is the preferred way to store these uploads so that failover exists and why?

  1. CDN, such as Amazon S3 / CloudFront.
  2. Store the images in MongoDB? I do this now and don't use GridFS cause our images are all under 1MB.
  3. Use some type of NFS with some sort of failover setup. If #3, then how do you configure this failover?

I use #2 just fine right now and have used #3 without the failover before. If I use MongoDB as the data store for my website and for serving images, could these GET requests for the images ever impact the performance of getting non-image data out of the DB?

like image 332
Bradford Avatar asked Apr 04 '11 14:04

Bradford


People also ask

Is it good idea to store images in MongoDB?

No, MongoDB is not a good place for storing files. If you want to store files, you should use storages like Amazon S3 or Google Could Storage. The good practice is to store the files in a storage and then to just save the URL of the uploaded image in the MongoDB.

What is the best way to store images in MongoDB?

If you need to store the actual file on MongoDB, then GridFS is the way to go (as suggested by @Sudhesh_Gnanasekaran). However there is an alternative – store a url to an image in your document.

Can MongoDB hold images?

There are three ways to store the images in MongoDB: GridFS, Within Document, and Referencing an external URL. If an image or any binary file which is of size less than 16MB can be stored in MongoDB using Binarydata ( bindata ) type.


2 Answers

could these GET requests for the images ever impact the performance of getting non-image data out of the DB?

Well, more image requests = more HTTP connections to your web servers = more requests for images from MongoDB = more network traffic.

So, yes, getting more image data from the DB could, in theory, impact getting non-image data. All you need to do is request 1000 images / sec at 1MB an image and you'll start seeing lots of network traffic between your MongoDB servers and your Web servers.

Note that this isn't a MongoDB limitation, this is a limitation of network throughput.

If you start getting lots of traffic, then the CDN is definitely recommended. If you already have an HTTP page that outputs the image, this should be pretty straight-forward.

like image 164
Gates VP Avatar answered Sep 16 '22 17:09

Gates VP


Why not a CDN in front of MongoDB?

like image 26
sdot257 Avatar answered Sep 20 '22 17:09

sdot257