Module graphql_rate_limit

Module graphql_rate_limit 

Source
Expand description

Request-count rate limiter for GraphQL API targets with pluggable algorithms.

Two strategies are supported via RateLimitStrategy:

  • SlidingWindow — limits outgoing requests to max_requests in any rolling window duration. Before each request rate_limit_acquire is called; it records the current timestamp and sleeps until the oldest in-window request expires if the window is already full.

  • TokenBucket — refills tokens at a steady rate (max_requests / window); short bursts are absorbed by the bucket capacity before the rate is enforced. Computes the exact wait time required to accumulate the next token instead of sleeping speculatively.

A server-returned Retry-After value can be applied via rate_limit_retry_after, which imposes a hard block until the indicated instant irrespective of the active algorithm.

Operates in parallel with graphql_throttle (leaky-bucket cost throttle). Both can be active simultaneously.

Re-exports§

pub use crate::ports::graphql_plugin::RateLimitConfig;
pub use crate::ports::graphql_plugin::RateLimitStrategy;

Structs§

RequestRateLimit
Shareable, cheaply-cloneable handle to a per-plugin sliding-window limiter.

Functions§

parse_retry_after
Parse an integer Retry-After value from a header string.
rate_limit_acquire
Sleep until a request slot is available within the rolling window, then record the slot.
rate_limit_retry_after
Record a server-returned Retry-After delay.