#What it is
Ledger is a usage-based billing engine for Go: meter events, check entitlements, compute invoices, manage plans and subscriptions, and integrate a payment provider.
#What it does
- Subscriptions: trials, upgrades, downgrades, cancellations, with proration.
- Metering: batched high-throughput ingestion, tested above 100k events per second.
- Entitlements: cached authorization checks in under a millisecond, because they end up on the hot path of every request rather than only at checkout.
- Pricing: graduated, volume, flat-rate and hybrid models.
- Invoices: line items, taxes, discounts, and a coupon system with percentage and fixed-amount validation.
#Two decisions worth calling out
Money is integer-only. There is no float anywhere in the codebase. Every rounding decision is explicit and happens at a named place, because the alternative is a reconciliation conversation with a finance team about half a cent.
Identifiers are TypeIDs: globally unique, K-sortable, and prefixed, so an id in a support ticket tells you what kind of thing it refers to without a lookup.
Storage is pluggable across PostgreSQL, SQLite, Redis and memory, and Chronicle integration gives the audit trail that billing disputes eventually require.