Providers

Local

In-process rate limiting with the lowest latency and no external dependencies.

The local provider keeps all state inside the current process.

Three paper-craft rate-limiter topologies showing local state, direct shared Redis state, and local state synchronized to Redis.
Local keeps state in one process; Redis centralizes every call; hybrid periodically synchronizes local state to Redis.

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 trypema::RateLimiterBuilder;
use trypema::local::LocalRateLimiterProvider;

let provider = LocalRateLimiterProvider::builder().build().unwrap();
let absolute = provider.absolute();
let suppressed = provider.suppressed();

Builders start stale-state cleanup by default. Configuration applies to both strategies exposed by the provider.

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.