Wednesday, November 21, 2007

Ideas on debugging your live website

I write this article to share my experience that I had in fixing bugs on live site. With users live on your site and transactions worth 100s of dollars ready to be executed, you cannot risk down time to fix the bug and get live again. So what do you do? You definitely cannot keep that bug there; you cannot down the site; you cannot disable the feature that has the bug? What would you do?

Here are some ideas that I have been using to identify and fix issues on live site:

1. Make extensive use of HTML Comments

The best way to debug is to output statements or data contained in variables while execution; but you dont want the debug statements to be visible to your live users. In this case make extensive use of HTML comments. Instead of directly outputting to your browser, you should enclose that output within a HTML comment tag

Once you have made necessary additions to your code and uploaded your script, you can check and validate your debug statements by viewing the source of the HTML output.

2. Log statements to a Database

Another way to debug your App is to log debug messages to a database. A problem with this approach is that debug statements of all users will start to appear in the database. To resolve this problem you should create a separate file that will create a cookie on your machine.

Your script should check for the existence of the cookie and if it exists should record the statements in the database.

Ideas like these should actually be part of the top level architecture of the site and should be implemented at the design time itself.

3. Create a copy of the script

This is a very easy way of debuging, but not always feasible when you have a workflow to test. Reserve this method for testing a page that is not part of a workflow i.e. the existance of which does not depend on the data being passed from another page. Though you can hard code the data being passed, but I would recommend to reserve this method to debug standalone pages.

Additional notes

Lastly, write code that you can maintain later. It is easy to get the code working initially during development, but when your client wants you to maintain that code base, that is where the problem starts if the code has not been written from the perspective of maintenance.

Leave behind comments if you have other ideas as well and would want to share.

No comments: