Skip to main content

Module limits

Module limits 

Source
Expand description

Rate limits that survive a second replica — RateLimits and shared.

ⓘ
// routes/api.rs
router.post("/login", login).middleware(limits::shared(
    ThrottleRequests::per_minute(5)
        .named("login")
        .keyed_by(|request| request.input("email")),
));

A bare ThrottleRequests counts in its own process, which is the right default for development and for a single node. Behind a load balancer it means five replicas each enforce “five attempts a minute” separately, and the real limit is twenty-five.

For a page-view limiter that is a rounding error. For a credential limiter it is the difference between a control and a decoration, which is why the bootstrap says so at boot when it finds one over a per-process cache.

Structs§

RateLimits
The store every shared limiter in this application counts in.

Functions§

shared
Count throttle in the application’s shared store.
warn_if_rate_limits_are_not_shared
Say so when a route rate-limits against a per-process counter.