If your user’s file needs to be more tightly coupled, secured, and confidential.Note: I've skipped some contradictory points to curtail the content because while comparing two things, we often end up finding that the pros and cons of one are the opposite of other. Have you ever thought about what happens when an RDBMS has to find and sort data? RDBMS tracks each data page - even the lowest amount of data read and written - and it has to track if it’s in-memory or if it’s on-disk, if it’s indexed or if it's sorted physically etc. Memory is ineffective. Often, RDBMSs are RAM-driven, so all data has to go to RAM first.Database backups will be more hefty and heavy.You may have to convert the files to blob in order to store them in the database.It's more secure than saving in a file system.Backups automatically include file binaries.Files will be in sync with the database and cannot be orphaned, which gives you the upper hand in tracking transactions.
ACID consistency, which includes a rollback of an update that is complicated when files are stored outside the database.Let’s see some pros and cons involved in saving files in the Pros of Database Though the file system comes with some costs and certain cons, a good internal folder structure and choosing a folder location that may be a little difficult to access by others can help. If your application will have a large number of users.If your application is responsible for handling large files (i.e.It's best to avoid saving in the file system if you cannot afford to compromise in terms of security. Low security. Since your files can be saved in a folder where you should have provided write permissions, it is prone to safety issues and invites trouble, like hacking.You might not know whether the file exists or not. Consider a scenario in which your files are deleted from the location manually or by some hacking dudes. There are no ACID (Atomicity, Consistency, Isolation, Durability) operations in relational mapping, which means there is no guarantee. It's easy to migrate it to cloud storage i.e.It's cost effective in most cases to expand your web server rather than pay for certain databases.You can just copy and paste the folder to your desired destination while ensuring that write permissions are provided to your destination. Migrating the data is an easy process.Downloading can be done by addressing a URL with the location of the saved file. Saving the files and downloading them in the file system is much simpler than it is in a database since a simple "Save As" function will help you out.In a files ystem, accessing a file is quite simple and light weight. To justify this, if you store large files in DB, then it may slow down the performance because a simple query to retrieve the list of files or filename will also load the file data if you used Select * in your query. Performance can be better than when you do it in a database.Let’s see some pros and cons involved in saving files in the file system. If you are accustomed to storing files in a file system and think that file system were created for the purpose of holding files, or if you are not bothered with the advantages of using a database for saving files in certain scenarios, then it’s time to reconsider your choices, my friend! This is because modern DBMS focuses on improving the storage of large blobs.
Later, I realized that understanding the circumstances and requirements paves the way for making the right choice. If you are indecisive in choosing the best way to save a file uploaded to your server, then cheers, mate! You're not alone.Īs a developer, sometimes I feel confused when asked to choose the optimal way of doing certain simple, yet conflicting things.