Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train's Rate Limiter Implementation #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

TrainTravel
Copy link

In this repo, a rate limiter class is implemented using the simple "Token Bucket Algorithm".

Then, in the ResourceController, a concurrentHashMap to hold a mapping between client's IP address and its own bucket(limiter). ConcurrentHasMap is used to ensure that the code is thread-safe.

With each successful request, client can see how many tokens are left in the header "X-Rate-Limit-Remaining".

When the client is rate-limited, the header includes "X-Rate-Limit-Retry-After-Seconds"

Unit tests were written.

Further improvements can be done in taken into consideration of using the functional endpoints provided by Spring Webflux.

And also, error handling haven't been added to the REST endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant