Token-bucket rate limiter with per-account and global buckets.
Each Aurinko access token gets its own bucket so one heavy account cannot starve others. A global bucket caps total outbound RPS.
Configuration
config :aurinko,
rate_limiter_enabled: true,
rate_limit_per_token: 10, # requests/second per token
rate_limit_global: 100, # requests/second total
rate_limit_burst: 5 # extra burst capacity above the per-second rateUsage
Normally consumed automatically by the HTTP client. You can also use it directly:
case Aurinko.RateLimiter.check_rate(token) do
:ok -> make_request()
{:wait, delay_ms} -> Process.sleep(delay_ms); make_request()
{:error, :rate_limit_exceeded} -> {:error, :too_many_requests}
end
Summary
Functions
Check and consume one token for the given access token.
Returns a specification to start this module under a supervisor.
Return current bucket state for a token (for debugging/monitoring).
Reset all buckets for a specific token (e.g. after a 429 with Retry-After).
Types
@type check_result() :: :ok | {:wait, non_neg_integer()}
Functions
@spec check_rate(String.t()) :: check_result()
Check and consume one token for the given access token.
Returns:
:ok— request may proceed immediately{:wait, ms}— caller should sleepmsmilliseconds and retry
Returns a specification to start this module under a supervisor.
See Supervisor.
Return current bucket state for a token (for debugging/monitoring).
@spec reset_token(String.t()) :: :ok
Reset all buckets for a specific token (e.g. after a 429 with Retry-After).