Local
The local provider keeps all state inside the current process.

Why choose Local
- lowest latency
- no Redis dependency
- simplest operational story
- ideal for single-service APIs, jobs, CLIs, and tests
What to expect
- keys are plain
&str - methods are synchronous
- state disappears when the process exits
- limits are not shared across instances
- both strategies expose live reads, conditional updates, and key lifecycle operations
- admission is best-effort under concurrent callers
Build it
use std::sync::Arc;
use trypema::RateLimiterBuilder;
use trypema::local::LocalRateLimiterProvider;
let provider: Arc<LocalRateLimiterProvider> = RateLimiterBuilder::local().build().unwrap();
let absolute = provider.absolute();
let suppressed = provider.suppressed();
LocalRateLimiterProvider::builder() is a shortcut for the same builder. Its build() needs no
annotation. Builders start stale-state cleanup by default. Configuration applies to both
strategies exposed by the provider.
Build one strategy directly
When the application uses one strategy only, build that limiter directly: annotate the result of
build() with the limiter type. The limiter does not create the state of the other strategy.
use std::sync::Arc;
use trypema::{RateLimit, RateLimitDecision, RateLimiterBuilder, WindowSize};
use trypema::local::AbsoluteLocalRateLimiter;
let limiter: Arc<AbsoluteLocalRateLimiter> = RateLimiterBuilder::local()
.window_size(WindowSize::minutes_or_panic(1))
.build()
.unwrap();
let rate = RateLimit::per_second_or_panic(10.0);
assert!(matches!(limiter.inc("user-123", &rate, 1), RateLimitDecision::Allowed));
For the suppressed limiter, annotate Arc<SuppressedLocalRateLimiter>. The shortcuts
AbsoluteLocalRateLimiter::builder() and SuppressedLocalRateLimiter::builder() need no
annotation. The limiter runs its own cleanup loop; see
Directly built limiters. For the settings and targets
of each backend, see Backends and targets.
The provider and each limiter return the window they were built with from window_size().
Best fit
Use local limiting when one process owns the traffic you care about or when you deliberately want each instance to enforce its own local budget.
If many instances must coordinate around the same limit, move to Redis or hybrid.

