Suppose you are tasked with writing a web application that must store configuration information in some format. What are the benefits and drawbacks for storing these configuration information in a relational database compared to storing the information in a file? Configuration options may include but not limited to data retention settings and settings for interfacing with external system (e.g. ip address, port, username, password).
Why is it better to store data in a database rather than in the file system?
Database provides a proper data recovery process while file system did not. In terms of security the database is more secure then the file system (usually).
Is database better than file system?
A file system does not allow for efficient data storage and retrieval. The use of a database management system is efficient because there are numerous techniques for storing and retrieving data. It does not provide data recovery services. In DBMS, there is a backup recovery option for data.
Should data be stored in files in a file system or in a database for the system?
Since the dawn of time, database vendors have called out to developers, “Store everything inside the database. You know you want to. Here, we'll make it easy for you by adding data types like binary and features like filestream.”
What are the advantages of storing the content in a database?
Databases support good data access because: Large volumes of data can be stored in one place. Multiple users can read and modify the data at the same time. Databases are searchable and sortable, so the data you need can be found quick and easily.
Here is a summary of pros and cons
Pros for file:
- Fast access to configuration data. (assuming no caching)
- Each server can be configured differently (in a load balancing situation)
- You already need a file for the database credentials so everything can be stored in one place.
Cons for file:
- Configuration in a load balanced environment is difficult.
- When adding settings under development, one most remember to move them into the files on every server in production.
- Configuration must be writable by the webserver if you want to write a control panel to change the settings at runtime. Manipulating files in a control panel is a hassle due to timing issues and or locking.
Pros for database:
- Load balancer can share configuration across the cluster
- It's very easy to check on settings remotely or change them such as in phpMyAdmin or a straight sql client.
- Control panel development becomes simple.
- Performance impact can be mitigated by caching configuration in memcached or in a hash in memory.
- Programmers are more likely to control settings rather than IT people or at least can be controlled through control panel.
Cons for database:
- Performance maybe slow if you're fetching the settings continuously.
- If you don't provide a tool, it might be more difficult for sysadmins to administer the product rather than a file. They might not be sql gurus.
- Clustering is more of a pain.
This comes down to personal preference and any current or possible future requirements for providing easy configuration.
And now a real answer.
I guess in the end it is a matter of taste
Pro:
- you could add an admin page to edit the settings in your applications
Con:
- if your database is not available, your settings are also gone
- if you migrate a database to a different environment (e.g. a production database to test to do some issue checking) your settings are included
- slightly harder to deploy
- more difficult to add to version control
- you need a file anyway to store your database credentials