Suppose we have a service
There are serveral interfaces:
quota:
- selector: pkg.svc.method
rate_limit:
unit: minute
request_per_unit: 2000
region: xxx
the interface of quota server:
RLS(RLSRequest) RLSResponse
The only one need to be stored in DB is the rate limiting config.
ServiceConfig(id, version, serialized_service_config)
Synchronization issue: in redis, apparently, the rate limiting service can sends read write requetss to redis concurrently and we relies on sortedSet in redis to handle the synchronization problem.
Rate limiter locations: client-side/server-side/middle ware
The api rate limiter can be put in many places, like client-side/server-side/middle ware. Client-side isn't a good choice as malicious clients can get ride of rate limiter. As for server-sde and middleware, middleware is a better choice as it can be shared with other services as a standard solution.
Rate limiting algorithm choices:
We choose the token bucket as it is very simple and straighitward. Leaking bucket could fill up the queue with old requests and if they are not processed in time, recents requests wil be rate limited.
The rate limiting service can be a bottlenecks if we have higher traffics so we can scale up the rate limiting service and also the redis.
Monitoring: we can add monitoring in the api gateway side to
The rate limiting service should be per location instead of global so that we can have better performance