Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing large number of images database or filesystem

Tags:

java

image

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.

  1. Database

    Storing images as base64 in database.
    we are working on a nosql database.

  2. File System

    To make an unique id and store it under an folder.

like image 258
Ramesh Avatar asked Oct 08 '22 09:10

Ramesh


2 Answers

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?

like image 165
Hemant Metalia Avatar answered Oct 13 '22 00:10

Hemant Metalia


There is a trade off - it will depend on your exact situation and needs. The benefits of each include

Filesystem

  • Performance, especially caching and I/O

  • Storing file paths in the database to be best.

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:

  1. Is it a good idea to store hundreds of millions small images to a key/value store or other nosql database?
  2. Storing images in NoSQL stores
like image 44
Somnath Muluk Avatar answered Oct 12 '22 23:10

Somnath Muluk