I’ve seen Jarrod Dixon’s solution (Best way to implement request throttling in ASP.NET MVC?) for implementing calls-per-second rate limiting. I’m now trying to figure out how to build a similar filter for N-calls-per-day.
I am building a developer API where free accounts get ~100 calls per day and paid accounts get a higher rate limit. What’s the best way to do calls-per-day rate limiting in MVC 3?
I don’t think that an in-memory structure would suffice here, due to the long duration that you need to measure. IIS recycling would be problematic in this case. As such, I’d recommend recording user access to the resource in the DB and only allowing a count of 100 in the last 24 hours.
On the other hand, here’s our implementation of a leaky bucket limiter (which is more handy for short term limiting where failure is relatively unimportant). Using .NET 4 concurrent collections might improve on the somewhat brute-force locking in this implementation: