When to use a database-driven Web site

Does your Web site really need a database? You might be surprised at the answer. Here are issues to consider before implementing a database-driven Web site.

Web sites require functionality, flexibility, and usability, though usability is often emphasized over other attributes. Notice that I didn’t mention a database. A database back end is a tool that helps fulfill a Web site’s requirements. Whether a Web site needs a database back end is a different matter.

Many friends ask me how to implement a database in their Web sites. Before I tell them how, I always ask why they want a database-driven Web site. To my surprise, many think a database is the only way to go. The buzz today is all about the supposed benefits of a database, yet few stop to consider whether they actually need a database or what the cost will be in performance or functionality.

Let's be clear: We’re referring to database-driven Web site content, not to collecting data or displaying data from other sources, or to data used in ways other than Web pages.

When to use a database
I use a database for all constantly changing content. For example, news sites need a database to keep track of articles. Another example is an intranet site I created for a quality assurance group. I set up a Web site that allows each member of the group to post all test cases to a back-end database.

How did I satisfy the requirements of functionality, flexibility, and usability? I created a central repository for the creation, retrieval, and searching of test cases, thus ensuring functionality and usability. I made the system flexible by adding features—namely, printing and editing capabilities.

When not to use a database
So when shouldn’t you use a database? Many of you are probably saying, “That’s ridiculous—you can always benefit from a database.” Let me explain why that isn’t always so.

How many Web sites use a database for the title, links, images, or text? Many do, but just because we can put site content into a database doesn’t mean that we need to. The fact is, some bottlenecks can come from using databases. There are potential network problems, connectivity issues, and authorization problems, not to mention the need for database management and maintenance.

There are some alternatives to databases for managing your Web site content. I like to store site data in configuration files that have arrays or other variables that can hold that data. Other choices might be XML files or text files.

You make the call
When creating a Web site, focus on the reasons for using a database back-end system to drive your site. Many times, it’s easier and faster to access required data from a configuration file than from a database.

We can take this one step further. By using the database for real data and not relatively static Web site data like site name, slogans, and such, we can alleviate pressure on the back end and increase overall performance. For example, if we have 15 queries to pull out Web site data and only three queries for actual data, think of the performance and usability gained by keeping site content and actual data separate.

Editor's Picks