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

  • compile-time validation of arguments when possible

Links

Package
Docs
Source

Showing Posts 1 to 9

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:

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
CodeSync
:microphone: ElixirConf 2026 - Call for Talks is open! We’re heading to Chicago :united_states: :round_pushpin: In person + virtual :d...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews