Guides
Configuration
Validated settings controlling windows, grouping, suppression, cleanup, and synchronization.
Every provider builder implements RateLimiterBuilder; Redis and hybrid builders add their
connection and namespace settings. Start with defaults, then tune only for a measured need.

Choose settings by behavior
| Goal | Setting | Tradeoff |
|---|---|---|
| Change enforcement horizon | WindowSize | longer windows smooth bursts but retain history longer |
| Change time precision | BucketSize | smaller buckets improve precision and increase state work |
| Shape gradual shedding | HardLimitFactor | larger values spread suppression across more traffic |
| Reduce factor recomputation | SuppressionFactorCachePeriod | longer periods can make pressure briefly less current |
| Bound inactive state | stale_after, cleanup_interval | faster cleanup performs more background work |
| Balance hybrid lag and Redis load | SyncInterval | shorter intervals reduce lag and increase Redis work |
| Isolate Redis state | prefix | cooperating instances must use the same namespace |
See Configuration Types for meanings, defaults, units, and
validation. build() also validates relationships such as BucketSize <= WindowSize regardless
of setter order.
Example
use std::time::Duration;
use trypema::{
BucketSize, HardLimitFactor, RateLimiterBuilder, SuppressionFactorCachePeriod, WindowSize,
local::LocalRateLimiterProvider,
};
let provider = LocalRateLimiterProvider::builder()
.window_size(WindowSize::minutes_or_panic(1))
.bucket_size(BucketSize::milliseconds_or_panic(10))
.hard_limit_factor(HardLimitFactor::new_or_panic(1.5))
.suppression_factor_cache_period(
SuppressionFactorCachePeriod::milliseconds_or_panic(100),
)
.stale_after(Duration::from_secs(600))
.cleanup_interval(Duration::from_secs(30))
.build()
.unwrap();
Keep settings consistent for Redis-backed instances sharing one namespace.

