Skip to content

Implement rate limiting using Bucket4j #174

Open
@nanotaboada

Description

@nanotaboada

Description

To prevent abuse and ensure fair usage of our RESTful API, we should implement rate limiting using Bucket4j, a Java rate-limiting library based on the token bucket algorithm. This will help improve system reliability and provide a better experience for all users.

Proposed Approach

  • Integrate Bucket4j via a filter or interceptor in the Spring Boot application.
  • Apply rate limiting at the controller level using IP-based or user-based keys.
  • Use an in-memory store for buckets (ConcurrentHashMap) in the first iteration.
  • Define rate limit configuration (e.g., 10 requests per minute) in a central config file or class.
  • Consider using annotations or AOP for cleaner integration if applicable.

Acceptance Criteria

  • Add Bucket4j dependency to the project.
  • Implement a filter/interceptor that applies rate limiting logic.
  • Protect at least one public-facing endpoint with rate limiting.
  • Return HTTP 429 Too Many Requests when rate limit is exceeded.
  • Log events when requests are throttled for observability.
  • Include basic unit and/or integration tests for the rate limiter.

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomersjavaPull requests that update Java code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions