Getting Started

Introduction

Start with the provider and strategy that match your workload, then scale without changing your mental model.

Trypema is a sliding-window rate limiting library for Rust with three providers and two strategies:

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.
ProviderBest forMain trade-off
Localsingle-process services, jobs, CLIsstate is not shared
Redisshared limits across many instancesevery check performs Redis I/O
Hybridvery high-throughput distributed APIsincrements reach Redis within SyncInterval; checks can be up to AllowedLag old
StrategyBest forBehavior
Absolutehard admission controlallow or reject
Suppressedgraceful degradationprobabilistic shedding near or above the limit

What Trypema is good at

  • Starting local and keeping one consistent model as deployment grows.
  • Using fractional rates such as 0.5 or 5.5 requests per second.
  • Running best-effort distributed limiting with Redis 7.2+.
  • Choosing between allow/reject admission and smoother traffic shedding.

What to keep in mind

  • Local state is process-local.
  • Redis and hybrid are best-effort distributed limiters, not strictly linearizable admission control.
  • redis-tokio and redis-smol are mutually exclusive.

The name

Trypema comes from the Koine Greek word "τρυπήματος" (trypematos), "hole" or "opening," from the biblical phrase "through the eye of a needle." The image fits the library well: a rate limiter is a narrow gate that controls what passes through.

  1. Installation
  2. Quickstart (Local)
  3. Quickstart (Redis) or Quickstart (Hybrid)
  4. Configuration Types and Decisions
  5. Providers