Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Billing Platform

A production-grade billing engine built in Rust — engineered for correctness, performance, and enterprise-scale complexity.

What It Does

The billing platform is a complete revenue operations engine. It handles every stage of the billing lifecycle, from tracking raw usage events to sending final invoices and collecting payment:

  • Metering — Ingest CloudEvents-compatible usage events at high volume. Aggregate by SUM, COUNT, MAX, or unique count across BillingPeriod, Sliding, or Tumbling windows.
  • Rating — Pure-function rating engine supporting flat, per-unit, graduated, volume, package, and committed pricing models with contract discount application (basis points) and tier overrides for enterprise custom pricing.
  • Invoicing — Full invoice lifecycle: Draft → Open → Paid or Void. Sequential invoice numbers (INV-XXXXXX), credit notes, proration, true-up billing, and progressive billing thresholds.
  • Contracts — Enterprise commercial contracts with ramp phases, escalation clauses, commit draw-downs, coterming, and immutable amendment chains.
  • Dunning — Automated failed payment retry with 4-attempt schedule (+3d/+7d/+14d/+21d post-failure).
  • Payments — Stripe integration for PaymentIntent creation, capture, refund, and webhook verification.
  • Tax — Pluggable TaxAdapter trait. Default: zero-tax pass-through. Swap in FlatRateTaxAdapter (basis points) or connect to Avalara/TaxJar in production.
  • Ledger — TigerBeetle-compatible double-entry ledger for AR, prepaid credit, and deferred revenue tracking.
  • Spend Alerts — Threshold-based SoftLimit (notify) and HardLimit (block charges) with reset workflow.
  • Credit Wallets — Prepaid top-up, drawdown, and auto-recharge via wallet credit service.
  • Audit Trail — Append-only audit log with 25+ action types, actor tracking, before/after state capture.

Key Design Principles

No floats, ever. All monetary amounts are i128 pico-units (scale=12). This eliminates floating-point rounding errors that plague billing systems. A $9.99 charge is stored as 9_990_000_000_000.

Purity where it counts. The rating engine, proration engine, and true-up calculations are pure functions — no I/O, fully deterministic, easily tested in isolation.

Idempotent by default. Every mutating operation accepts an Idempotency-Key header. The platform caches responses for 24 hours, making all operations safe to retry after network failures.

Enterprise-ready. Multi-entity customer hierarchies (parent/subsidiary/cost-center), consolidated billing, multi-currency support, B2B tax exemptions, and RBAC-ready auth.

Technology Stack

Rust · Axum · TigerBeetle (ledger) · CockroachDB (CRDB multi-region) · ClickHouse (metering analytics) · Kafka (event streaming) · Stripe (payments) · Redis (rate limiting, hot-path accumulators)


Ready to get started? Head to the Quick Start guide.