dotnet-starter-kit
dotnet-starter-kit copied to clipboard
Implement Rate Limiting in ASP.NET Core
Is your feature request related to a problem? Please describe. When building APIs, regardless of the framework and language you are using, you may want to limit the number of requests an API accepts within a window of time. This is done by rate-limiting strategy which helps to limit the network traffic.
Describe the solution you'd like limit for IpAddress, PerUser, PerApiKey
Describe alternatives you've considered https://github.com/stefanprodan/AspNetCoreRateLimit https://www.nuget.org/packages/AspNetCoreRateLimit/ https://medium.com/swlh/rate-limiting-a-net-core-application-bf245bc0d76b
Not sure rate limiting is something you'd want to implement at the API level... Consider the case with a load balancer and multiple instances of your app. You'd want the rate limiting to happen at the load balancer, not at each individual app...
Had an interesting conversation about this earlier on the fastendpoints discord here.
Maybe for a small app that only has one instance it would be handy that it is built into the api itself. But for anything larger I think this is a sysop concern (no concern of the app developer).
So if we were to implement something like this, it should be fully driven off of configuration so it can be easily turned off or on, or taken out and put in a separate service at a higher level. Something like a middleware probably.
Might be worth looking into Polly's Rate Limiting and Bulkhead policies?
Should be implemented at Load Balancer Level.