A high-performance rate limiter library for Go applications with multiple rate limiting strategies.
Rate is a high-performance rate limiter library for Go applications designed to control request frequency and prevent system overload. It provides multiple algorithmic strategies including token bucket, AIMD (Additive-Increase/Multiplicative-Decrease), and rotating token bucket to handle different rate limiting requirements in concurrent environments.
Go developers building high-throughput concurrent systems such as API servers, backend services, and distributed systems that require precise and efficient rate limiting to manage traffic and prevent overload.
Developers choose Rate for its ultra-fast performance with core operations in single-digit nanoseconds and zero allocations, its thread-safe design using optimized atomic operations for high concurrency, and its multiple specialized strategies that go beyond basic token buckets to handle scenarios like adaptive backend protection and collision resistance.
A high-performance rate limiter library for Go applications
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Core operations like CheckToken execute in 5.919 nanoseconds with zero allocations, enabling hundreds of millions of operations per second as shown in benchmarks.
Offers TokenBucketLimiter, AIMDTokenBucketLimiter for adaptive control, and RotatingTokenBucketLimiter for collision resistance, covering diverse rate limiting scenarios beyond basic token buckets.
Uses optimized atomic operations and sharded buckets to ensure thread safety without lock contention, making it suitable for high-concurrency environments as highlighted in the design philosophy.
Employs packed token bucket representations and custom 56-bit timestamps to minimize memory usage, with each bucket using only 8 bytes, as detailed in the implementation.
Choosing the optimal number of buckets requires understanding collision probabilities and load factors from the advanced usage section, which can be non-trivial and error-prone for developers.
Lacks out-of-the-box HTTP middleware or framework support, requiring manual integration for common use cases like API rate limiting, as it focuses on core algorithms only.
The RotatingTokenBucketLimiter uses twice the memory and token consumption for collision resistance, with a performance overhead of ~2x compared to the standard token bucket, as noted in its trade-offs.
Designed for in-memory rate limiting on a single server, with no native support for distributed rate limiting across multiple instances, limiting its use in scaled-out architectures.