Storing Images : DB or File System - Storing Images : DB or File System - database database

Storing Images : DB or File System -


Putting all of those images in your database will make it very, very large. This means your DB engine will be busy caching all those images (a task it's not really designed for) when it could be caching hot application data instead.

Leave the file caching up to the OS and/or your reverse proxy - they'll be better at it.


Some other reasons to store images on the file system:

  • Image servers can run even when the database is busy or down.
  • File systems are made to store files and are quite efficient at it.
  • Dumping data in your database means slower backups and other operations.
  • No server-side coded needed to serve up an image, just plain old IIS/Apache.
  • You can scale up faster with dirt-cheap web servers, or potentially to a CDN.
  • You can perform related work (generating thumbnails, etc.) without involving the database.
  • Your database server can keep more of the "real" table data in memory, which is where you get your database speed for queries. If it uses its precious memory to keep image files cached, that doesn't buy you hardly anything speed-wise versus having more of the photo index in memory.