4 ms·
For those working in a Java JAX-RS environment and looking for an additional rate filter on the app server itself, here is a similar Redis+Lua rate limiter impl
by cobbzilla 8y ago
For those working in a Java JAX-RS environment and looking for an additional rate filter on the app server itself, here is a similar Redis+Lua rate limiter implemented as a Jersey/JAX-RS filter [1].
It supports multiple limits, for example max 100 requests/minute and 10000/day, etc. The lua magic is here [2].
[1] https://github.com/cobbzilla/cobbzilla-wizard/blob/master/wizard-server/src/main/java/org/cobbzilla/wizard/filters/RateLimitFilter.java https://github.com/cobbzilla/cobbzilla-wizard/blob/master/wi...
[2] https://github.com/cobbzilla/cobbzilla-wizard/blob/master/wizard-server/src/main/resources/org/cobbzilla/wizard/filters/api_limiter_redis.lua https://github.com/cobbzilla/cobbzilla-wizard/blob/master/wi...
- zaroth 8y agoThis isn’t using the same rate limiting approach as OP which follows the CloudFlare suggestion of a simplified sliding window which counts lastInterval/thisInterval instead of just a current interval counter that will reset in a single instant. For daylong limits the single interval count may be less than ideal if a burst of activity happens to cross the reset threshold, the allowed rate will be double the expected limit. Also, I think a trivial optimization would be to remove the GET call and just call INCR.