cristipufu / aspnetcore-redis-rate-limiting

Set up a Redis backplane for ASP.NET Core multi-node deployments, using the built-in Rate Limiting support that's part of .NET 7 and .NET 8.
MIT License
234 stars 25 forks source link

Manual Replenishment #199

Open gorillapower opened 2 days ago

gorillapower commented 2 days ago

Are there any plans to implement a ReplenishmentRatelimiter version of the current Redis Ratelimiters?

In my case, im trying to prevent 429s on a downstream api endpoint, but it looks like due to network latency and/or timing issues, this cannot be guaranteed.

An alternative is to manually control the replenishment ourselves to guarantee that the request has started/ended before we replenish the ratelimiter.

gorillapower commented 2 days ago

Ive added a RedisReplenishmentSlidingWindowLimiter implementation in the following repo https://github.com/gorillapower/aspnetcore-redis-rate-limiting.

Basically, im just keeping track of two counters. One tracks the ratelimit window, as was before, the other tracks the replenishment tokens, which can only be replenished manually by calling the TryReplenish() method.