ASP.NET Web API Request Throttling with Redis Cache

When developing API’s for external parties to consume, sometimes the need for request throttling becomes relevant. In this article you’ll see a simple approach to create such a middleware component for Web API in ASP.NET 5, based on Redis. You can browse or download the complete sample on GitHub at: https://github.com/jlandersen/web-api-redis-request-throttling. Considerations The general case usually is that you have identifiable consumers of your API. The consumers are usually identified based on an access key (or something equivalent) supplied with each request. Since you will have to check each incoming request up against a history of previous requests, the mechanism should almost always be implemented using in-memory caching or a dedicated caching system, such as memcached or Redis. Before implementing a request throttling mechanism in your API, that rates each of these consumers individually, you should consider how ambitious the mechanism should be. You can choose from a wide range of different parameters to base the rating on. Some examples are: ...

August 16, 2015 · Jeppe Lund Andersen