Saturday, 29 December 2007

On web application configuration

There are two common approaches for configuring web applications:

  • Configuration file(s) in the web application's directory
  • Storing configuration data in the database

What sort of data am I talking about:

  • Email setup (where to send response form, error emails etc, whether to send mail to customers etc)
  • Setup of things which need to vary between development and production - payment service provider configuration, setup of other third party integration things
  • Error handler configuration (whether to display errors, where to log them, email them etc)
  • Enabling / disabling features (for example, debug things)
  • Visual stuff or branding (labels etc)

Clearly the database connection string needs to be stored somewhere too, but that can't be in the database for obvious reasons.

Database configuration

pros: does not need to be configured on each web server of a farm; not accidentally overwritten by new deployments
cons: bad for hierarchical or structured data; performance overhead; difficult to maintain configuration data stored in a database in SCM. Modifications require apply/ rollback scripts

Configuration files

pros: Easy to manage in SCM (like all your other files, even if not in the same place); less runtime performance overhead; better for hierarchical data; database connection string can be held with other items.
cons: Needs to be synchronised across a web farm; care should be taken that the right versions are always deployed everywhere.


For a larger application with a web farm, using a database for some configuration is clearly beneficial. If you have many servers and/or servers of other types (non-web servers), they can store all their configuration in a central database. If performance is a problem, copies can be cached locally.

For a small simple application, configuration files are better- they're more manageable generally. I prefer to put most configuration in a file if possible.

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.