Configuration parameters – In database or in config files?

November 24, 2006

Every application either accicentaly or by design, ends up having some system configuration parameters in the database and some in the configuration ( .ini or .xml or .config) files. But where are they better placed?

Lets look at config files:

  • If the application uses databases, the database to connect to must be there in the config files, so this cannot be eliminated.
  • There are some environment properties (outside our applications) which the runtime reads from the config files. they cannot be moved to database as well.
  • Its usually easy to edit config files using any text editor.
  • Its easier for development as it doesnot require any infrastructural code to read these parameters from the database.
  • It is easy to distribute these.
  • In the case of clustered application, the same parameters need to be synchronised to all nodes in the cluster.
  • There are chances of making a mistake while editing it.
  • In case there are multiple environments, maintaining different files with most common, but some different values is cumbersome.

Now lets look at databases.

  • In case of changing a parameter in a cluster – we need to do that only once. 
  • We need to write a small piece of code to efficiently load these values from the database, and keep them in memory for future use.
  • We could allow for dynamic update of these parameters, but there would be a lot more code if this needs to be cached and all.
  • We can provide an interface for users to change these.
  • These parameters are easier to change and maintain as one change reflect in all machines.
  •  In case of multiple environments, we could keep the parameters on these servers, and these parameters will not be affected when a new application deployment happens.
  • For adding new parameters, SQL scripts need to be created for all environments.

So what does it mean? Which way to go?

In my experience, I prefer to keep as much in the database as possible, leaving in the config files only those which are inevitable, like the Database connection string, session parameters etc.

I also tend to have a simple application which can be used to maintain any set of name value pairs – which we use for editing the database.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: