mokies / ratelimitj

A Java library for Rate-Limiting, providing extensible storage and application framework adaptors.
Apache License 2.0
482 stars 93 forks source link

Return which limit rule was reached #4

Open ofirnk opened 7 years ago

ofirnk commented 7 years ago

We love your published library and very likely to use it.

One idea to improve is to return not just a simple boolean but a rich object of type {isOverLimit:boolean, limitingRule:RequestLimitRule} or similar. Exact type is not critical, it's just the idea of letting the user (be it internal or external) - which limit was reached.

So currently - the user would just get false when she's limited. After - she'd know what exactly blocked her access.

WDYT?

p.s I know it's a major refactor to internal logic + interface.. but it can be done in a non-breaking mode

mokies commented 7 years ago

Yes it is a good idea and something I am considering as it maybe useful to return counts to upstream clients like so:

Status: 200 OK X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4999 X-RateLimit-Reset: 1372700873

This is something that Github's API has https://developer.github.com/v3/rate_limit/

ofirnk commented 7 years ago

Exactly what I was targeting!

coi18n commented 3 years ago

Craig, we are making extensive usage of your library to control/limit some protocols. Works like a charm so far (combined with Redis). Returning which limit rule was reached is definitively an important tuning feature. Many thanks for your great job.