A Java rate-limiting library based on the token-bucket algorithm, offering high precision and support for both local and distributed scenarios.
Bucket4j is a Java library that implements rate limiting using the token-bucket algorithm. It allows developers to control the frequency of operations, such as API calls or resource access, to prevent abuse and ensure system stability. The library supports both local in-memory buckets and distributed scenarios across multiple JVMs.
Java developers building applications that require rate limiting, including web APIs, microservices, and distributed systems where controlling request rates is critical.
Developers choose Bucket4j for its high precision, performance-optimized design, and extensive support for distributed backends. Its flexibility as a library, rather than a framework, allows for seamless integration into existing codebases.
Java rate limiting library based on token-bucket algorithm.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses integer calculations exclusively to avoid floating-point rounding errors, ensuring accurate token consumption and refill rates as highlighted in the README.
Default lock-free implementation provides excellent scalability for multi-threaded environments, reducing contention and improving performance in high-concurrency scenarios.
API optimized with primitive types minimizes boxing and garbage collection, making it suitable for performance-critical applications as stated in the features.
Supports numerous backends like Redis, JDBC, and MongoDB for clustered rate limiting, with async APIs for non-blocking operations in distributed setups.
Builds for Java 8 are not available on Maven Central, requiring manual downloads from the website, which complicates dependency management and setup.
As a library, it requires writing Java code for integration; while a Spring Boot starter exists, non-Spring users face a steeper learning curve and more boilerplate.
Some distributed backends lack features like asynchronous support (e.g., Jedis) or flexible expiration, as noted in the compatibility tables, limiting choices for certain use cases.