Skip to main content

RateLimitStore

Trait RateLimitStore 

Source
pub trait RateLimitStore: Send + Sync {
    // Required method
    fn check<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        limit: u32,
        window: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision, Box<dyn Error + Sync + Send>>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
}
Expand description

A distributed rate-limit backend (ADR 0015): the authority a cluster shares so a client’s budget is enforced across replicas, not per-process.

The base framework’s default limiter is in-process (fine for a single instance, and documented as such); a deployment that runs several replicas behind a load balancer wires a shared store (e.g. Redis) through this port so one client cannot get N × limit by spreading requests across instances. The check must be atomic in the backend (a single round trip that increments and expires), not a read-modify-write, so concurrent replicas cannot race past the limit. Rate limiting is abuse-dampening, not a durable business guarantee, so a store that is briefly unavailable fails open at the call site by default. The call site may override this — a deployment fronting auth/OTP, for which an unthrottled window is worse than shedding load, can choose to fail closed (e.g. seiva-http’s DistributedRateLimit::on_store_error).

Required Methods§

Source

fn check<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, limit: u32, window: Duration, ) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision, Box<dyn Error + Sync + Send>>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Records one hit for key and reports whether it is within limit per window. Implementations increment-and-expire atomically.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§