Tracking usage of public resources - throttling accesses per hour

Hi,

We have an application that allows the user to define a publicly available resource with an ID. The ID can then be accessed via an HTTP call, passing the ID. While we're not a picture site, thinking of a resource like a picture may help understand what is going on.

We need to be able to stop access to the resource if it is accessed 'x' times in an hour, regardless of who is requesting it.

We see two options
- go to the database for each request to see if the # of returned in the last hour is within the limit.
- keep a counter in each of the application servers and sync the counters every few minutes or # of requests to determine if we've passed the limit. The sync point would be the database.

Going to the database (and updating it!) each time we get a request isn't very attractive.

We also have a load balanced farm of servers, so we know 'x' is going to have to be a soft limit if we count in the app serevrs. (We know there will be a period of time between syncing the counts in the app servers where we'll overshoot the limit. That is okay since we'll catch the limit violation and stop the requests.)

Other thoughts on how do to this?

Thanks,

Chris