I am working on a project where we need to store large no of images say some 10 millions so which is the best way to store the images.Best way in terms of speed and efficient.
It is a web based project so the image retrieval should be fast.
-
Database
Storing images as base64 in database.
we are working on a nosql database.
-
File System
To make an unique id and store it under an folder.
1)Database
- will require much code for processing image as using streams
- Heavier load on the database server
- database storage is usually more expensive than file system storage
- databases win out where transactional integrity between the image and metadata are important.
- it is more complex to manage integrity between db metadata and file system data
- it is difficult (within the context of a web application) to guarantee data has been flushed to disk on the filesystem
2) File system
- To store images on a unique id and storing it to harddisk will be a better option .
- things like web servers, etc, need no special coding or processing to access images in the file system
refer http://perspectives.mvdirona.com/2008/06/30/FacebookNeedleInAHaystackEfficientStorageOfBillionsOfPhotos.aspx
also see Storing Images in DB - Yea or Nay?
There is a trade off - it will depend on your exact situation and needs. The benefits of each include
Filesystem
There are a couple of issues:
- database storage is usually more expensive than file system storage
- you can super-accelerate file system access with standard off the shelf products
- for example, many web servers use the operating system's sendfile() system call to asynchronously send a file directly from the file system to the network interface. Images stored in a database don't benefit from this optimization.
- things like web servers, etc, need no special coding or processing to access images in the file system
- databases win out where transactional integrity between the image and metadata are important.
- it is more complex to manage integrity between db metadata and file system data
- it is difficult (within the context of a web application) to guarantee data has been flushed to disk on the filesystem
Database
- Easier to scale out to multiple web servers
- Easier to administer (backup, security etc)
If you have a SQL 2008 DB, have a look at FileStream in this SO article - this gives the best of both worlds.
See Storing Images in DB - Yea or Nay?
Edit
See for Nosql:
- Is it a good idea to store hundreds of millions small images to a key/value store or other nosql database?
- Storing images in NoSQL stores