Add a Redis-backed token bucket RateLimiter implementation
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is your feature request related to a problem? Please describe the problem.
In the runtime repo, we have included a bunch of built-in, in-memory `RateLimiter` implementations like `ConcurrencyLimiter`, `FixedWindowRateLimiter`, `SlidingWindowRateLimiter` and `TokenBucketRateLimiter`. It would be nice to add a rate limiter that works across multiple hosts in a distributed environment. In the past, for things like our `RedisCache` `IDistributedCache` implementation, we've used StackExchange.Redis to implement a solution in the aspnetcore repo for a runtime abstraction. I think we should do the same things for this.
### Describe the solution you'd like
I think we should implement a token bucket `RateLimiter` based on Redis using StackExchange.Redis that can be used in distributed environments. I imagine the options for this rate limiter will be a combination of what's in [TokenBucketRateLimiterOptions](https://github.com/dotnet/runtime/blob/315549e9ece8ff5d5b04316a62c1b73f7370cff2/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiterOptions.cs) and [RedisCacheOptions](https://github.com/dotnet/aspnetcore/blob/29f8aa30564aebf3365b57011498212831715b64/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs).
We might want to make it easier to reuse existing `IConnectionMultiplexer` since there will likely be multiple instances by default. Another way to avoid unnecessary Redis connections might be to implement `PartitionedRateLimiter` instead of `RateLimiter`.
@BrennanConroy @wtgodbe
### Additional context
Customers are [asking for this.](https://github.com/dotnet/aspnetcore/issues/37380#issuecomment-1137813130)
Contributor guide
Assessment
This issue has not been assessed yet.