pub trait RateLimiterBackend:
Send
+ Sync
+ 'static {
// Required methods
fn check<'a>(
&'a self,
bucket_key: &'a str,
config: &'a RateLimitConfig,
) -> Pin<Box<dyn Future<Output = Result<RateLimitResult>> + Send + 'a>>;
fn build_key(
&self,
key_type: RateLimitKey,
action_name: &str,
auth: &AuthContext,
request: &RequestMetadata,
) -> String;
// Provided method
fn enforce<'a>(
&'a self,
bucket_key: &'a str,
config: &'a RateLimitConfig,
) -> Pin<Box<dyn Future<Output = Result<RateLimitResult>> + Send + 'a>> { ... }
}Expand description
Pluggable rate-limiter implementation.
The runtime exposes two implementations:
HybridRateLimiter: per-node DashMap fast path with PG fallback forGlobalkeys. Approximate under multi-node deployments — user/IP limits multiply by the node count. Right for DDoS protection.StrictRateLimiter: every check round-trips to PostgreSQL. Cluster-wide correct. Right for billing-grade or quota enforcement.
Both ship with the framework. Users implement this trait themselves only when their backing store sits outside the runtime’s PG-only contract.
Required Methods§
Sourcefn check<'a>(
&'a self,
bucket_key: &'a str,
config: &'a RateLimitConfig,
) -> Pin<Box<dyn Future<Output = Result<RateLimitResult>> + Send + 'a>>
fn check<'a>( &'a self, bucket_key: &'a str, config: &'a RateLimitConfig, ) -> Pin<Box<dyn Future<Output = Result<RateLimitResult>> + Send + 'a>>
Check whether a single token is available for the given bucket.
Sourcefn build_key(
&self,
key_type: RateLimitKey,
action_name: &str,
auth: &AuthContext,
request: &RequestMetadata,
) -> String
fn build_key( &self, key_type: RateLimitKey, action_name: &str, auth: &AuthContext, request: &RequestMetadata, ) -> String
Build the bucket key string for a (key kind, action, auth, request) tuple.
Provided Methods§
Sourcefn enforce<'a>(
&'a self,
bucket_key: &'a str,
config: &'a RateLimitConfig,
) -> Pin<Box<dyn Future<Output = Result<RateLimitResult>> + Send + 'a>>
fn enforce<'a>( &'a self, bucket_key: &'a str, config: &'a RateLimitConfig, ) -> Pin<Box<dyn Future<Output = Result<RateLimitResult>> + Send + 'a>>
Check and convert a denial into a ForgeError::RateLimitExceeded.