TallyMan

A usage-metering pipeline that stays exact when the events don't cooperate — duplicates, late arrivals, and out-of-order streams all reconcile to the same billable total.

Kind

Metering / Billing

Stack

Rust, Postgres

Status

design

USAGE EVENTS BILLING SDK meter HTTP ingest ingest dedup key windows event-time watermark lateness gate rollups billable immutable event log append-only source of truth — rollups recompute from here reconcile past window invoices closed periods · append-only
Fig 7.1 — Events → idempotent ingest → event-time windows → rollups → invoices

Status — design, not yet built. This is a spec written in the project voice so it can be evaluated as a design. The correctness numbers below are the shape of the report the harness will produce (Δ = 0 is the target, not a measured result). It earns a place on the shelf only once the harness run backs it up.

The Problem

A usage event — customer X consumed Y units at time T — looks trivial until it meets production. The same event arrives twice because a client retried. An event shows up ten minutes late because a phone went through a tunnel. Events arrive out of order. A consumer crashes halfway through aggregating a window. Six weeks later a customer disputes an invoice and you have to prove the number.

Get any of these wrong and you either over-bill — chargebacks, churn, a support queue — or under-bill and quietly leak revenue, and the worst part is you can't tell which happened. Most pipelines "handle" this with an at-least-once queue and hope.

Usage-based billing is the most universal correctness problem in SaaS, and almost everyone gets late, duplicate, and out-of-order events subtly wrong.

The Approach

TallyMan ingests usage events at volume and turns them into billable rollups that stay exact under adversarial input. The design leans on a few decisions that do most of the work:

Staying exact when events don't cooperate

The interesting engineering is in the failure modes, not the happy path — the same discipline the DropBear merge and idem.sh idempotent verbs are built on, pointed at money instead of files.

The proof — a correctness report

The design is only worth anything if it's shown, so the centerpiece is an adversarial harness that injects each failure mode into the same event stream and checks the billed total against ground truth. The target is a single column of zeros.

ScenarioEventsDuplicatesLate (> window)Out-of-orderBilledTruthΔ
Clean1,000,000000
20% client retries1,000,000200,00000
Late arrivals1,000,000050,0000
Out-of-order1,000,00000100,000
Consumer crash mid-window1,000,000
Adversarial (all at once)1,000,000200,00050,000100,000
Invariant disabled (control)1,000,000200,00000≠ 0

The last row is the SearchLab move: deliberately switch off the idempotency check and show the total drift, because a result you can only trust by measuring should be shown drifting when the guard is gone. A throughput/latency row (events/s, p99 ingest) rides alongside so the same page answers "is it exact" and "does it scale."

Where it stands

A design, not a running system — written up here so the shape can be judged before it's built. The plan is to ship the exactness proof and the throughput numbers first on a single node (Postgres as both the append-only log and the rollup store), and leave real Kafka ingestion, multi-node aggregation, and any UI as stated gaps. The correctness report alone is the deliverable; a half-built "platform" is not. Promote off design status — and onto the featured shelf — only once the Δ = 0 column is real.

Δ = 0 Billed total vs ground truth under duplicates, lateness & reordering
exactly-once Effect-level idempotency on at-least-once delivery
event-time Windows gated by a watermark, not arrival order
append-only Closed periods correct by adjustment, never in-place edits