An Elixir rate-limiter with pluggable backends and multiple algorithms for API requests, file uploads, and more.
Hammer is an Elixir library for implementing rate limiting in applications. It allows developers to set limits on actions like API requests or file uploads within specific time windows, helping to prevent abuse and manage resource usage. The library supports multiple storage backends and rate-limiting algorithms to accommodate different performance and precision needs.
Elixir developers building web APIs, microservices, or any application that requires controlled access to resources, such as SaaS platforms, gaming backends, or network services.
Developers choose Hammer for its pluggable architecture, which allows them to select the most suitable backend and algorithm for their use case, from simple fixed windows to precise sliding windows, all within a unified Elixir-native interface.
An Elixir rate-limiter with pluggable backends
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports ETS, Atomic, Redis, and Mnesia backends, allowing developers to choose between single-node speed (e.g., ETS default) or distributed scalability (e.g., Redis) based on deployment needs, as detailed in the backend documentation.
Implements Fixed Window, Leaky Bucket, Token Bucket, and Sliding Window algorithms, providing precise control for different use cases like burst tolerance or smooth traffic, with a comparison guide in the README to aid selection.
Offers atomic backends for high-speed single-node operations and includes benchmarks in BENCHMARKS.md, demonstrating efficiency for scenarios like API rate limiting with minimal overhead.
Well-documented with tutorials, guides (e.g., distributed ETS), and Hexdocs, making it easier for developers to implement features like sliding windows or distributed setups without guesswork.
Sliding window algorithm is only available for the ETS backend, restricting its use in distributed setups with Redis or Mnesia where precision might be needed, as shown in the algorithm-backend compatibility table.
Using distributed backends like Redis requires additional dependencies (e.g., separate hammer-backend-redis package) and configuration, adding overhead compared to simpler, all-in-one rate limiting solutions.
The default fixed window algorithm has boundary issues allowing up to 2x requests at window edges, requiring manual workarounds like bursty counters, which the README admits and suggests implementing with extra checks.