Skip to content

Rate Limiter written in elixir with configurable backends

License

Notifications You must be signed in to change notification settings

Frameio/ex_limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ex_limiter

Rate Limiter written in elixir with configurable backends

Implements leaky bucket rate limiting (wiki), which is superior to most naive approaches by handling bursts even around time windows. You can define your own storage backend by implementing the ExLimiter.Storage behaviour, and configuring it with

config :ex_limiter, :storage, MyStorage

usage once configured is:

case ExLimiter.consume(bucket, 1, scale: 1000, limit: 5) do
  {:ok, bucket} -> #do some work
  {:error, :rate_limited} -> #fail
end

Additionally, if you want to have multiple rate limiters with diverse backend implementations you can use the ExLimiter.Base macro, like so:

defmodule MyLimiter do
  use ExLimiter.Base, storage: MyStorage
end

ExLimiter.Plug

ExLimiter also ships with a simple plug implementation. Usage is

plug ExLimiter.Plug, scale: 5000, limit: 20

You can also configure how the bucket is inferred from the given conn, how many tokens to consume and what limiter to use.

About

Rate Limiter written in elixir with configurable backends

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages