One rust rate limiter for in-memory and distributed workloads.

Trypema gives you one API for in-process, Redis-backed, and hybrid sliding-window rate limiting. Start with a single service, then scale to distributed systems without switching libraries or changing mental models.

Cargo.toml
[dependencies]
trypema = "1"
main.rs
use trypema::{RateLimit, RateLimitDecision, RateLimiter};

let rl = RateLimiter::builder().build().unwrap();
let rate = RateLimit::try_from(10.0).unwrap();

match rl.local().absolute().inc("user_123", &rate, 1) {
    RateLimitDecision::Allowed => { /* proceed */ }
    RateLimitDecision::Rejected { retry_after_ms, .. } => {
        eprintln!("retry in {retry_after_ms}ms");
    }
    RateLimitDecision::Suppressed { .. } => unreachable!(),
}

Three providers, one model

Pick the deployment shape you need today. The provider API stays familiar as you move from one machine to many.

    Local

    In-process state with the lowest latency and the least operational overhead. Best for single services, workers, CLIs, and tests.

    Redis

    Best-effort distributed limiting with one Redis round-trip per call. Use it when multiple instances must share limits directly.

    Hybrid

    Local fast-path plus periodic Redis sync. This is the highest-throughput distributed option when per-request Redis I/O is too expensive.

Two strategies

Choose the admission style that matches your failure mode.

    Absolute

    Deterministic sliding-window limiting. Requests are either allowed or rejected, with best-effort retry hints on rejection.

    Suppressed

    Probabilistic shedding near or above capacity. Instead of an abrupt cliff, suppression increases as pressure rises.

What Trypema is built for

    Fractional rates

    Rate limits are f64, so 0.5 req/s and 5.5 req/s are first-class inputs.

    Sliding windows

    Smooth request accounting without fixed-window resets. Bucket coalescing lets you tune precision versus overhead.

    Background cleanup

    Cleanup can start automatically from build() or manually through run_cleanup_loop() when you construct from explicit options.

    Runtime-aware Redis support

    Enable exactly one of redis-tokio or redis-smol. Redis-backed providers require Redis 7.2+.

Start here

    Getting Started

    Install the crate, create a limiter, and choose a provider quickly.

    Concepts

    Learn how keys, rates, windows, and decisions fit together.

    Providers

    Compare local, Redis, and hybrid tradeoffs before you commit to one.

    Benchmarks

    See where each provider is fastest and what the numbers do and do not mean.