06 May 2011

Storing Uploaded Files in a Database or in the File System

There was a requirement in one of our project where we need to upload document from .NET web application. The options were less either to Sql Server Database or File System. Share point option was ruled out because of internal issues. Sharing one of the comparison study we made that time, might be helpful to someone who is looking for the same. 

It requires less work - Storing and retrieving binary data stored within the database involves more code than when working with the data through the file system. It's also easier to update the binary data - no need for talking to the database, just overwrite the file!
Performance - Since the files are stored on the file system rather than on the database, the application is accessing less data from the database, reducing the demand on the database and lessening the network congestion between the web and database server. Database operations are more costly than file system.
Storage Limit: Storing files in the DB is great for small files and if we are sure that the size will not grow out of expectations.  In SQL Server we have limited options when you exceed the physical storage capacity of the box. The bulky database makes may creates problems in backing up the data, moving the data from one database server to another, replicating the database, and so on, is much easier because there's no worry about copying over or backing up the binary content stored in the file system. Taking backup and recovery will be more time consuming with Database storing.
Security: File system storage is great, but keep in mind that you're going to have to keep file permissions or security in mind than you would if you stored them in the DB.
Advantages of storing Binary Data in the Database...
1.    Enforcing referential integrity
2.    Tighter security as you doesn’t have to grant the web user account write access to a folder it is serving content from. Also you get the security of the sql server
3.    All files are backed up when the db is backed up
I would recommend having a shared drive where we can upload files and can store the file path in DB. That will be more simple and best solution. If we are having any issues of getting shared rive, storing in DB is definitely a solution. But we should be able to estimate the volume of the file to be stored. 

No comments: