governor
A GCRA-based rate-limiting library for Rust, supporting no_std and async use
Repository Health
Technical Analysis
governor implements the Generic Cell Rate Algorithm (GCRA) for rate limiting in Rust, exposing direct (single-key), keyed (per-client), and stream/sink-based rate limiters with jitter support to avoid thundering-herd retries. It works in both std and no_std environments and integrates with async runtimes via futures-based streams and sinks.
As a general-purpose rate-limiting primitive, governor is widely used as the backing implementation for framework-specific middleware — including actix-governor and tide-governor — letting Rust web frameworks add rate limiting without each reimplementing GCRA themselves.
What You Get
- GCRA (Generic Cell Rate Algorithm) rate limiting with
RateLimiterfor direct, single-key limits - Keyed rate limiters (backed by
HashMaporDashMap) for per-client/per-key limiting - Jitter support to spread out retry attempts and avoid thundering-herd effects
no_stdcompatibility for embedded and resource-constrained environments- Async integration via
futures-based stream and sink wrappers
Common Use Cases
- Rate-limiting incoming requests per API key or per IP address in a Rust web service
- Backing rate-limiting middleware for frameworks like actix-web (
actix-governor) or tide (tide-governor) - Throttling outbound calls to third-party APIs with strict rate limits
- Implementing rate limiting in
no_std/embedded Rust contexts where the standard library is unavailable
Under The Hood
Architecture - The crate’s core algorithm lives in gcra.rs, which implements the Generic Cell Rate Algorithm’s state machine (tracking a theoretical arrival time per key), while state/ provides the storage backends (in-memory HashMap/DashMap for keyed limiters, and a single-cell store for direct limiters); middleware.rs and the stream/sink integrations in the test suite (tests/streams.rs, tests/sinks.rs) layer async ergonomics on top of the same core GCRA state without duplicating the rate-limiting logic itself.
Tech Stack - A ~1,834-line no_std-compatible Rust library (edition 2018) with a minimal dependency footprint, optionally pulling in dashmap for concurrent keyed storage and futures/futures-executor for async stream/sink support; benchmarks use criterion, and property-based testing uses proptest with recorded regression cases (tests/proptests.regressions).
Code Quality - The test suite spans 11 dedicated integration test files (custom_hashers, keyed, keyed_hashmap, keyed_dashmap, direct, future, streams, sinks, middleware, memory_leaks, proptests) alongside criterion benchmarks, indicating deliberate coverage of both correctness and memory behavior; however, GitHub activity data shows very low recent commit velocity, suggesting the crate is stable/feature-complete rather than under active new-feature development.
API Design - The primary entry point, RateLimiter::direct() or RateLimiter::keyed(), is small and composable, and the crate’s no_std support and Clock abstraction (for injecting custom time sources, e.g. in tests) reflect careful attention to embedding governor into other libraries’ internals rather than only end-user application code — which is reflected in its adoption as the rate-limiting engine underneath other frameworks’ middleware crates.
Used by 3 apps in this directory
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
CubeSandbox
Developer Tools · Security · AI Agents
Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.
Vaultwarden
Password Manager · Security
Unofficial Bitwarden-compatible server in Rust — run the full Bitwarden ecosystem on a Raspberry Pi using every official client you already have, without the multi-container overhead.