Gewthen
Gewthen

Reputation: 408

What are the pros and cons for using a database to store configuration information compared to a File System

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).

Upvotes: 6

Views: 5842

Answers (3)

Pleun
Pleun

Reputation: 8920

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

Upvotes: 3

Lucas Holt
Lucas Holt

Reputation: 3826

Here is a summary of pros and cons

Pros for file:

  1. Fast access to configuration data. (assuming no caching)
  2. Each server can be configured differently (in a load balancing situation)
  3. You already need a file for the database credentials so everything can be stored in one place.

Cons for file:

  1. Configuration in a load balanced environment is difficult.
  2. When adding settings under development, one most remember to move them into the files on every server in production.
  3. 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:

  1. Load balancer can share configuration across the cluster
  2. It's very easy to check on settings remotely or change them such as in phpMyAdmin or a straight sql client.
  3. Control panel development becomes simple.
  4. Performance impact can be mitigated by caching configuration in memcached or in a hash in memory.
  5. Programmers are more likely to control settings rather than IT people or at least can be controlled through control panel.

Cons for database:

  1. Performance maybe slow if you're fetching the settings continuously.
  2. 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.
  3. Clustering is more of a pain.

This comes down to personal preference and any current or possible future requirements for providing easy configuration.

Upvotes: 3

Will Hartung
Will Hartung

Reputation: 118744

Because then all you have to do is have your connection pool properly configured (which you should have to do anyway), and then you know where all of your settings are located. Plus they can be updated at runtime, they be updated with the app up or down, and they can't be stomped on with when the application is deployed.

All sorts of good reasons.

Upvotes: 1

Related Questions