spring-cloud / spring-cloud/spring-cloud-gateway
Dynamic rate limits per route.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Is your feature request related to a problem? Please describe.
I would like to implement something like a dynamic rate limiter. This is, suppose you have an exposed service, but you have observed that this service has some request's peaks at determined intervals of time.
For example you might have a service that receives 90% of the time an average of X request per minute (rpm) per origin but you have noticed that the 10% left occurs always between 9am and 10am and this 10% has an average of 2X rpm and this is normal because of the content the service serves, so you want to allow this traffic.
My question is if it is possible to make/use a RequestRedisRateLimiter filter to response dynamically depending on time of the day, day of the week, etc.
Describe the solution you'd like
I would like to establish a route gateway like the following:
builder.routes().route(p -> p
.path("/api")
.and()
.header("Authorization")
.and()
.filters(f -> f.requestRateLimiter().configure(
c->c.setRateLimiter(this.redisRateLimiter()));})
.uri("http://localhost:8080/api"))
.build()
where once the gateway receives a request, the RedisRateLimiter will allow or deny the request but with a different limit/burst depending on the time of the day.
Describe alternatives you've considered
I have been knocking my head trying to write my own filter based on RequestRateLimiterGatewayFilter, establishing multiples routes (like the code above) and adding custom predicates where the predicates check for the time day and give only access to the gateway with the right route.
None of them have worked, either because I have not the knowledge to achieve this dynamic rate fitler solution or because it is not even possible with spring cloud gateway redis rate limiting.
Additional context
To me it does not sound as a bizarre idea, it is a quite simple concept. From monday to friday I have an average traffic so I establish a rate limiter based on this traffic. These same days, between 9am and 10am my traffic suffers a peak of request so I want my service to increase its limits and bursts. Anyway I have not find nothing similar on the web.
If anyone could help with ideas or possible solutions/workarounds it would be great!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the RequestRateLimiterGatewayFilter and RedisRateLimiter concepts referenced in the issue, then trace how requestRateLimiter().configure supplies limiter settings for a route. Compare that flow with the proposed time- and day-based limits and determine whether the current API supports changing rate and burst dynamically. Done would require a documented design or implementation path, including tests for the scheduled limits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100