Marqeta.RateLimiter (marqeta v1.0.0)

Copy Markdown View Source

Token-bucket rate limiter for the Marqeta API.

Maintains per-category token buckets. When a bucket is empty, callers block until tokens refill on the next 100 ms tick.

Buckets

BucketDefault RPSBurst
:default50100
:diva2050
:simulations1020

The limiter is started automatically by Marqeta.Application and is called by Marqeta.Client before every outbound request. In tests the GenServer is not started so the call is a no-op.

Summary

Functions

Acquires a rate-limit token for the given path.

Returns a specification to start this module under a supervisor.

Functions

check_rate_limit(path)

@spec check_rate_limit(String.t()) :: :ok

Acquires a rate-limit token for the given path.

Blocks (up to 10 s) if the relevant bucket is empty. Returns :ok once a token has been acquired.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@spec start_link(term()) :: GenServer.on_start()