Candil.RateLimiter (Candil v3.0.0)

Copy Markdown View Source

Global sliding-window rate limiter backed by ETS.

Replaces the per-process Process.get/1/Process.put/2 approach so that rate limits apply globally across all processes using the same circuit breaker.

The ETS table is created lazily on first access. Each breaker name has its own sliding window of recent request timestamps.

Summary

Functions

Checks whether a request for breaker is within the rate limit. Returns :ok or {:error, Candil.Error.t()} with the retry-after delay in milliseconds.

Starts the rate limiter ETS table.

Functions

check(breaker, max_per_second)

@spec check(binary() | atom(), pos_integer() | nil) ::
  :ok | {:error, Candil.Error.t()}

Checks whether a request for breaker is within the rate limit. Returns :ok or {:error, Candil.Error.t()} with the retry-after delay in milliseconds.

start_link(opts \\ [])

@spec start_link(keyword()) :: :ignore

Starts the rate limiter ETS table.

Safe to call multiple times — second call is a no-op.