marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul

Home Page:https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic rate limiting

Jodee90 opened this issue · comments

Is your feature request related to a problem? Please describe.
Trying to limit a continuously growing API may be hard. It needs constant monitoring of incoming number of requests and constantly updating the rate limiter's configuration with the proper numbers. What will happen if there is a specific date that is triggering more traffic, but it is acceptable(e.g Black Friday, Marketing period etc)?

Describe the solution you'd like
Since the spring boot comes with a lot of extra functionality for metrics (actuator, micrometer, prometheus etc) we could use these analytics for things such as req/sec and adjust the rate limiter as we go. For a simple case of a general policy that limits the requests coming to our gateway, we calculate and keep the median of Requests/TimeUnit (e.g requests/10s). Then when refresh-interval kicks in, we recalculate the median and so on. If the past X median values are above the threshold that we initially defined, we can adjust the rate limiter to the new threshold. Since this could lead to an infinite increase of the threshold there must be an upper limit. This limit can either be some percentage, time limit or plain number.

For example, let's say we have the following default policy:

  • limit: 5
    refresh-interval: 2
    type:
    • dynamic:
      reEvaluationPeriod: 2minutes
      upperLimit: 15

We limit access to 5requests per 2seconds but since we have type as dynamic we keep the median value of incoming requests each time a refresh interval window is being triggered. Every 2 minutes we reevaluate the policy saying that if the media values of incoming requests is more than 5 then we need to adjust to the new rate limit to that new value, but this "new value" should never exceed the 15req per 2seconds. When the time passes by and the requests are being decreased again, we reevaluate the policy back to it's lower limit, the 5req per 2seconds.

Is there something over here that i may have overlooked? Any use case? Any thoughts?

Hello @Jodee90, thanks for getting in touch, we will get back to you asap! If you have issues in the 1.x.x.RELEASE line we recommend you to update to the latest version, unfortunately this line is not supported anymore.

Hi, @Jodee90 thanks for taking your time and making this suggestion. Unfortunately, it won't be added to this library at this time.
The library already offers ways to refresh its configuration properties, and the dynamic calculation for the rate-limiting goes beyond its purpose for the time being.

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 1 day