Prompt
Usage-based billing system for SaaS
Latest observation
Oct 15, 2026
OpenAI APIWeb search: off
A usage-based billing system for SaaS charges customers based on what they actually consume, rather than a flat subscription alone. It usually tracks metered events, aggregates usage, applies pricing rules, and generates invoices.
Core building blocks
-
Event collection
- Capture usage events from your product, e.g.:
- API requests
- seats active
- storage used
- compute minutes
- messages sent
- Events should include:
- customer/account ID
- metric name
- quantity
- timestamp
- metadata (region, plan, source, etc.)
- Capture usage events from your product, e.g.:
-
Metering / aggregation
- Convert raw events into billable usage.
- Common aggregation windows:
- real-time
- hourly
- daily
- monthly
- Handle deduplication and late-arriving events.
-
Pricing engine
- Apply pricing models:
- per unit
- tiered volume pricing
- graduated pricing
- included free units + overage
- commit + overage
- Support plan-specific rates and discounts.
- Apply pricing models:
-
Rating
- Convert usage into charges.
- Example:
- first 1,000 requests free
- next 9,000 at $0.002/request
- above that at $0.001/request
-
Invoice generation
- Produce line items from rated usage.
- Support taxes, credits, coupons, prorations, and adjustments.
-
Payments and collections
- Charge cards, ACH, invoicing, retries, reminders, dunning.
-
Reporting
- Usage dashboards, customer portals, revenue analytics, anomaly detection.
Typical architecture
- Product app emits usage events
- Event pipeline ingests events reliably
- Metering service aggregates usage
- Billing engine calculates charges
- Invoice service generates invoices
- Payment processor collects payment
- Customer portal shows usage and estimates
A common backend stack:
- API service + message queue/Kafka
- Event store or warehouse
- Billing rules service
- Relational DB for invoices/subscriptions
- Background jobs for invoicing and retries
Important design considerations
- Idempotency: avoid double-charging the same event
- Late data: decide whether to rebill or freeze periods
- Time zones: billing periods should be unambiguous, usually UTC
- Auditability: every charge should trace back to raw usage
- Scalability: high-volume event ingestion
- Plan changes: proration and mid-cycle pricing changes
- Accuracy vs latency: real-time estimates may differ from final invoice
Common pricing patterns
1. Flat subscription + usage overage
- Base fee includes some usage
- Extra usage billed on top
2. Pure usage-based
- Pay only for what is used
3. Tiered pricing
- Unit price changes by volume thresholds
4. Commit + overage
- Customer commits to minimum spend
- Overages billed if they exceed included amount
5. Seat-based + usage-based hybrid
- Fixed per seat, plus variable consumption
Data model basics
Typical entities:
CustomerSubscriptionPlanMeterUsageEventUsageAggregatePriceBookInvoiceInvoiceLineItemPaymentCreditNote
Example usage event:
{
"event_id": "evt_123",
"customer_id": "cus_456",
"meter": "api_requests",
"quantity": 1,
"timestamp": "2026-10-15T12:34:56Z",
"metadata": {
"endpoint": "/v1/search",
"region": "us-east-1"
}
}
Implementation tips
- Use append-only usage events as source of truth.
- Store raw events separately from aggregated usage.
- Make billing runs reproducible from historical data.
- Keep a pricing version for every charge.
- Build a reconciliation job to compare product usage vs billed usage.
Build vs buy
Build if:
- pricing is highly custom
- you need deep product integration
- usage logic changes frequently
Buy if:
- you want faster launch
- standard billing models are enough
- you prefer using Stripe/Chargebee/Orb/Recurly, etc.
If you want to build it
A practical MVP sequence:
- Define meters and event schema
- Ingest and store raw usage events
- Aggregate by customer and billing period
- Implement pricing rules
- Generate invoices
- Add dashboards and usage estimates
- Add retries, credits, taxes, and audits
If you want, I can also give you:
- a system design diagram
- a database schema
- a sample billing algorithm
- or a Stripe-based implementation plan