A question that I hear too frequently is “Whether I should save uploaded files, and photos to the DB or to my file-system”
First, let me give you my answer – FileSystem!!!
… and here is why-
* Though, wish modern DB engines such as MSSQL 2008, the access to either is as fast, storing your files on the DB requires an extra step of translating the query to a stream output. A step that can be easily avoided by letting the browser and the IIS handle the file fetching .
* Using the same repository to store your files and data will be very costly if you ever decide to improve your application performance by moving photos to a CDN (Content Delivery Network).
* For shared hosting – usually your DB space is limited, storing the files there will increase the DB size significantly.
* The dreadful word, every DBA hates – bottleneck! A major consideration when designing a software is to keep the queries to a minimum. Thus reducing bottlenecks, and ensuring rapid execution of queries. Saving files to your DB will create too many necessary queries, and potentially bottlenecks.
* Caching – though you can cache data fetched from your DB as well, letting the IIS treat files as static will save you a lot of space, code and headache.
* On a more personal note – sometimes we build websites (mostly ecommerce, or photography) that requires images in different sizes (thumbs), re-creating and resizing on the fly may proof very costly, what we usually do is resize the photo upon the first request, and save it as a file in the filesystem, the second time a visitor request for that image in that size, the file already exists, so the IIS will deliver it as an ‘unchanged’ file, reducing execution time, use resources .
Would love to hear your thoughts…

