I have a simple rule when it comes to writing to the database; it should be considered like spanking a child:
- Only do it when it is really, absolutely necessary
- Feel a little guilty every time you do it
- If you are doing it too often, seek professional help
Sure, this is a little tongue-in-cheek, but there is a pretty serious side to it to. The other day on Slashdot I saw a discussion on managing open file/record locks in a database, and a 'marked informative' suggested solution was to update a date field in the database every 10 seconds via Ajax, with an overall 30 second window to allow for network failures/etc. In other words, what was proposed (and popularized) was that every active record should call home every 10 seconds merely to say somebody is looking at it. Gads!!!!! This would add a huge amount of wasted database processing to an application and performance drain on a grand scale (especially if it required transactions and/or write locks).