liamkillingback

liamkillingback

Every SaaS I have built on Phoenix ended up with the same three hand-rolled pieces: count what each customer uses, stop them at their plan’s limit, and bill for the rest. There is no Elixir equivalent of Laravel Cashier for the billing half, and OpenMeter ships SDKs for Node, Python and Go but not for us. So I extracted the layer I kept rewriting into a library.

Aurora Meter does the counting and gating in a free MIT core:


# count: an ETS increment, nothing touches the database
AuroraMeter.track(org, :ai_generations)

# gate, run and meter atomically
AuroraMeter.with_quota(org, :ai_generations, fn ->
  generate_report()
end)
# => {:ok, result} | {:error, :limit_exceeded} | {:error, :not_entitled}

Plans are a small compile-time DSL with hard caps, metered overage and feature flags:

defmodule MyApp.Plans do
  use AuroraMeter.Plans

  plan :free do
    limit :ai_generations, 50, :hard
  end

  plan :scale do
    metered :ai_generations, included: 1_000, unit_price: 2
    feature :api_access, true
  end
end

How it is built. Increments hit a shared ETS table with :ets.update_counter/4, so there is no GenServer per tenant and nothing on the database write path. A single flusher persists snapshots to Postgres on an interval and on shutdown, and a broadcaster fans live values over PubSub. Two LiveView components read those counters, so a usage bar in your admin updates within a second of the increment on the server. Here it is with a burst of traffic driven from the BEAM:

usage-meter

with_quota/4 reserves first (increment, compare, roll back on breach), runs the function, and releases the reservation if it raises. The reservation is the usage, so two concurrent calls cannot both squeeze through the last unit of a hard limit.

The bundled benchmark (mix aurora_meter.bench 8 500000, dev laptop, Elixir 1.20 / OTP 29) does about 7.9M increments/s across distinct counters, and about 53k/s when all eight processes hammer one counter. The run is in the repo under docs/evidence.

What it does not do yet, honestly:

  • Buffered by default: a hard crash can lose up to one flush interval of increments. Durable features exist for anything you invoice.
  • Periods are UTC calendar months in the core. Postgres only.

Links: Hex · HexDocs · GitHub:

The core is MIT forever, no email gate. There is a paid Pro package for when Stripe should start charging (checkout, webhook sync, usage reported to Billing Meters, dashboards), but everything above is in the free library.

I would genuinely like to hear what metering shapes people have hand-rolled in their own apps, and what you would want gated that this does not cover.

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