a3kov

a3kov

Atomic Bucket

Fast single node rate limiter implementing Token Bucket algorithm. The goal is to provide dependable solution that JustWorks™ with a focus on performance, correctness and ease of use. Bucket data is stored using :atomics module. Bucket references are stored in ETS and optionally cached as persistent terms.

Features

  • lock-free and race-free with compare-and-swap operations

  • BlazingFast™ performance, see benchmarks section in the readme. Req/s go brrrrrr

  • monotonic timer for correct calculations

  • millisecond tick supporting wider range of parameters and preventing request starvation

  • automatic calculation of bucket parameters based on target rate and burst size (for fixed cost requests)

  • handy timeouts for retries

  • support for token “refunds” and variable cost requests

  • multiple rate limit checks in 1 atomic operation

  • compile-time validation of arguments when possible

Links

Package
Docs
Source

Showing Posts 1 to 10

Asd

Asd

This is a great library. The implementation is much more efficient and does not contain concurrency bugs like Hammer’s leaky bucket implementation.

Definitely gonna use it in one of my projects. One request is to leave the atomics ref management to the user!

PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

TIL that :atomics exists :smiley: great library and very interesting implementation! How did you learn about atomics and how did it lead to this library?

a3kov

a3kov OP

You have much more experience in Elixir than me so that is indeed strange.
In fact I’ve learned a lot from your blog posts in my Elixir journey.

It’s used in many libraries. Perhaps it’s a new trend to build stuff on top of it :rofl:

PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

Haha, thank you! I must now write a little blog post about atomics and will have to name you in it! That’s what you’re getting for sharing your good work online! Take that :winking_face_with_tongue:

jsm

jsm

If you’re interested, this uses atomics as well: Once - Ecto type for globally unique 64-bits IDs generated by multiple Elixir nodes (to be precise, the underlying NoNoncense lib does).

jsm

jsm

This is really cool :slight_smile:

a3kov

a3kov OP

v0.1.3 fixes a stupid but nonetheless serious bug. Please update if you are using the library for anything important.

a3kov

a3kov OP

Version 0.2.0 comes with new advanced features via raw_request/5:

  • Support for variable request cost for cases where multiple operations have different cost, but share the same budget.
  • Support for negative cost (“token refunds”). Can be useful where an allowed operation failed and we don’t want it to “steal” the budget.

Unless some new ideas appear the library seems feature-complete at this point.

a3kov

a3kov OP

Version 0.3 is out with benchmarking improvements and perf. optimizations:

  • 20-30% faster for buckets of normal size on 64bit
  • extremely big buckets and 32bit architectures will take a hit

Overall I think it’s a good trade-off - for now I don’t want to maintain 2 code paths and runtime checks would defeat the purpose. 64 bit and buckets typical for rate limiters is what most people use. This was a good case for me to learn about big integers on BEAM :blush:

a3kov

a3kov OP

Version 0.4 is out with a new feature.

Requires Elixir >=1.17 and Erlang >=27 (I want to use new toys :wink:)

New feature: enforce multiple rate limits in a single atomic operation via multi_request/4.
It covers cases where higher short-term rates must be allowed without making the burst instant, while enforcing lower sustained long-term rates.

Lazy refills in raw_request/5 (I figured it’s harmless so it’s now a bit faster).

Bucket cleanup should now run faster and consume less memory.

Where Next? Top

Trending in Announcing Top

mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
quatermain
Hello, I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself. I use Claude Code daily on a pr...
New
gtcode
Aloha gang, There’s a new class of AI model out from TypeSafe. Jev is their flagship model. You can learn about it here: ...
New
LostKobrakai
I’ve recently created a small library phoenix_vite integrating the vite build tooling with phoenix. It provides an igniter.installer t...
New
danschultzer
I needed something like premailer for rails, and after searching, I decided to make an easy-to-use library to handle inline styles and co...
New
kraleppa
If you’ve ever had to debug a BEAM node you know it can be a painful process. Parsing raw data, or dealing with clutter often gets in the...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
CodeSync
Code BEAM Europe 2026 – Call for Talks is Open! We’re excited to announce that Code BEAM Europe 2026 is now open for talk submissions :t...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews