Prompt
billing infrastructure for SaaS
Latest observation
Nov 24, 2026
OpenAI APIWeb search: off
A solid billing infrastructure for a SaaS usually includes these parts:
1) Core billing components
- Customer accounts / orgs
- Plans & pricing: monthly, yearly, usage-based, tiered, per-seat
- Subscriptions: start, upgrade, downgrade, cancel, pause
- Metering / usage tracking: API calls, storage, compute, seats, events
- Invoices: generation, taxes, discounts, credits, proration
- Payments: cards, ACH, wallets, retries, dunning
- Refunds / chargebacks
- Ledger / accounting records: immutable record of charges and payments
2) Typical architecture
- Product app
- emits billing-relevant events
- Usage event pipeline
- collects metered usage
- validates, deduplicates, aggregates
- Billing service
- subscription logic
- pricing calculation
- invoice generation
- entitlement checks
- Payment processor integration
- Stripe, Adyen, Paddle, Braintree, etc.
- Notification service
- invoice emails, payment failed, renewal reminders
- Admin console
- support overrides, comping, manual invoices, credits
- Data warehouse / analytics
- revenue metrics, churn, MRR, ARR, cohort analysis
3) Important design principles
- Use an immutable ledger
- never overwrite billing history
- Idempotency everywhere
- prevent duplicate charges/events
- Separate entitlement from payment status
- paid vs active access can differ
- Support proration
- upgrades/downgrades mid-cycle
- Handle retries and grace periods
- failed payments shouldn’t instantly cut access
- Auditability
- every billing action should be traceable
4) Key data models
CustomerOrganizationSubscriptionPlanPriceUsageEventInvoiceInvoiceLineItemPaymentCreditNoteLedgerEntryEntitlement
5) Common SaaS billing flows
- Signup
- create customer + trial
- Trial end
- convert to paid or suspend
- Upgrade
- immediate proration or next-cycle change
- Usage billing
- aggregate usage at end of period
- Failed payment
- retry schedule + email + grace period
- Cancellation
- end of term or immediate stop
- Refund
- issue credit note and adjust ledger
6) Build vs buy
- Buy if you want speed and fewer edge cases:
- Stripe Billing, Chargebee, Recurly, Paddle
- Build if you need:
- complex pricing
- custom metering
- enterprise invoicing
- multi-entity accounting
- strict control over billing logic
7) Recommended minimum setup
If you’re starting, a practical stack is:
- Stripe Billing for subscriptions and invoices
- Internal usage service for metering
- Webhook processor for payment events
- Postgres for billing records
- Background jobs for retries/dunning
- Admin UI for support actions
If you want, I can also give you:
- a reference architecture diagram,
- a database schema, or
- a Stripe-based implementation plan for SaaS billing.