Skip to content

[POC] Replace custom token bucket with Quarkus Bucket4J extension#3506

Closed
adutra wants to merge 1 commit intoapache:mainfrom
adutra:bucket4j-rate-limiter
Closed

[POC] Replace custom token bucket with Quarkus Bucket4J extension#3506
adutra wants to merge 1 commit intoapache:mainfrom
adutra:bucket4j-rate-limiter

Conversation

@adutra
Copy link
Contributor

@adutra adutra commented Jan 22, 2026

This change replaces the custom rate limiter implementation with the Quarkus Bucket4J extension, which provides a more robust and well-tested rate limiting solution.

The RateLimiter interface is preserved (since it might be an "extension point"), and the default implementation (RealmTokenBucketRateLimiter) now delegates to Bucket4J via a @RateLimited annotated method with per-realm segmentation.

Key changes:

  • Add quarkus-bucket4j dependency to gradle/libs.versions.toml
  • Create RealmIdentityResolver for per-realm rate limit segmentation
  • Rewrite RealmTokenBucketRateLimiter to use Bucket4J via self-injection
  • Add 'enabled' flag to RateLimiterFilterConfiguration
  • Update configuration to use Bucket4J properties:
    • quarkus.rate-limiter.buckets.polaris.limits[0].permitted-uses
    • quarkus.rate-limiter.buckets.polaris.limits[0].period
  • Update Helm chart with simplified configuration

Checklist

  • 🛡️ Don't disclose security issues! (contact security@apache.org)
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

This change replaces the custom rate limiter implementation with the Quarkus Bucket4J extension, which provides a more robust and well-tested rate limiting solution.

The `RateLimiter` interface is preserved (since it might be an "extension point"), and the default implementation (`RealmTokenBucketRateLimiter`) now delegates to Bucket4J via a `@RateLimited` annotated method with per-realm segmentation.

Key changes:

- Add quarkus-bucket4j dependency to gradle/libs.versions.toml
- Create `RealmIdentityResolver` for per-realm rate limit segmentation
- Rewrite `RealmTokenBucketRateLimiter` to use Bucket4J via self-injection
- Add 'enabled' flag to `RateLimiterFilterConfiguration`
- Update configuration to use Bucket4J properties:
  - `quarkus.rate-limiter.buckets.polaris.limits[0].permitted-uses`
  - `quarkus.rate-limiter.buckets.polaris.limits[0].period`
- Update Helm chart with simplified configuration
@adutra adutra force-pushed the bucket4j-rate-limiter branch from 625776f to e087219 Compare January 22, 2026 13:49
@snazy
Copy link
Member

snazy commented Jan 22, 2026

I think it's worth to investigate this approach as well, either in addition to or a replacement of #3507, as it would work for a horizontally-scaled Polaris instance.

@adutra
Copy link
Contributor Author

adutra commented Jan 26, 2026

I think it's worth to investigate this approach as well, either in addition to or a replacement of #3507, as it would work for a horizontally-scaled Polaris instance.

Yes, I think this approach only makes sense if/when there is desire for a distributed token bucket.

@snazy
Copy link
Member

snazy commented Jan 26, 2026

Yes, I think this approach only makes sense if/when there is desire for a distributed token bucket.

Are you saying that we should see how users want to implement rate-limiting in the wild?

@adutra
Copy link
Contributor Author

adutra commented Feb 6, 2026

Closing the PoC for now as we went with Guava's RateLimiter.

@adutra adutra closed this Feb 6, 2026
@github-project-automation github-project-automation bot moved this from PRs In Progress to Done in Basic Kanban Board Feb 6, 2026
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.

2 participants

Comments