New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distributed rate limiter? #350
Comments
No, we don't have a distributed cache for rate limiters. |
Is it something worth looking at? Thanks |
@storozhukBM Correct me if I'm wrong, but my opinion is that Rate Limiters should be fast and not decrease response times and throughput. Maybe you need a centralized ratelimiter inside of a load balancer or proxy instead. |
In lieu of some form of shared state for your rate limiters, what is the suggested approach for implementing rate limiting in an elastic/cloud environment? Using a single load balancer or proxy would create a single point of failure, so I don't think that's going to work for a lot of use cases. |
There is no approach for the implementation of our current rate limiter. @storozhukBM started with an implementation. |
One way I guess it could be done is if a bunch of counters are pre generated for each node and each node gets a range and when it has exhausted it's range and goes back and gets more from the cache... Something like this: https://apacheignite.readme.io/docs/id-generator |
Do you want to implement rate limiting at client-side (source) or server-side (sink)? If you want to have rate limiting at server-side and have a rate limit per client, you could use an API Gateway like Kong. |
Resilience4j-ratelimiter is better used at client-side. A client can also be another server. |
I don't think that you should use Resilience4j to reimplement an API gateway your own. |
Netflix already implemented an adaptive bulkhead: https://github.com/Netflix/concurrency-limits |
Totally agree with @RobWin on his thoughts. For me adaptive capacity management looks like ideal solution in your case. If it is not feasible/suitable for you for some reason, I'd recommend you to pre-calculate target throughput per node and configure it statically. If your cluster is truly elastic and it is shrinking and growing under load it automatically means that you have some coordination solution (service discovery like consul or eureka, maybe some other type of coordination), in this case you already have some unavoidable shared state, so it would be convenient to use it to dynamically reconfigure your rate limiters on each node. In this case, cluster configuration changes it is relatively rare event of disturbance and all other time everything will work without unnecessary state sharing. |
There are more scenarios I think where shared state rate limiting is a good option - for example where you don't control the target system and where your source system scales dynamically for other reasons, and where rate limit usage may not be the same between all clients in the cluster. |
Yes, but this would require a complete revision (overhaul) of our metric calculation and storage components. |
Haha yes ok understood, but that's not what was being pointed out previously. I'm just on the hunt for such a solution and came across all this stuff, so wanted to link them together for other people to also find :) |
@RobWin do you have a general idea of what components we would need to change to support this? I also came across this thread and althoguh there seem to be alternatives, they don't seem as good as resilience4j. |
Hi, unless I missed it. Will there be support to back the rate limiter by a distributed cache? Usually for fault tolerance, performance etc... We deploy at least 2 APIs side by side... So somehow the rate limiter would have to know between the API instances the count?
The text was updated successfully, but these errors were encountered: