Design a Subscription Billing System
Design a SaaS billing platform that manages subscriptions, charges customers on recurring schedules, prorates plan changes mid-cycle, tracks usage-based metering, handles failed payments with smart retry, and generates invoices with tax calculations.
The interesting problems are not "how do I charge a card" — the payment rails are assumed to exist (Stripe, Adyen, etc). The interesting problems are:
- Subscription state machine — trialing, active, pastdue, canceled, unpaid — with precise transition rules and side effects per transition. - Proration math when a customer upgrades mid-cycle, downgrades, adds seats, or switches plans. - Dunning — the retry logic for failed charges, including smart retries keyed off decline codes. - Usage-based billing with late-arriving events, aggregation windows, and idempotent metering. - Financial correctness — payments must never double-charge; invoices must match revenue recognition rules (ASC 606); credits, coupons, and tax must compose correctly. - Webhooks to customers' systems on every subscription event with at-least-once delivery guarantees.
Scope: a platform serving 100K SaaS merchants with 100M end-customer subscriptions, processing 10M billing events per day.
Suggested time: 90 minutes
Loading the workspace...
About this problem
Subscription billing is easy to describe and hard to build correctly. Every SaaS company has one, and nearly every SaaS company has at some point double-charged a customer, failed to invoice for usage, or lost revenue to dunning bugs. The reason is that "the happy path" looks trivial — charge a card, mark an invoice paid — but the real product is the dozens of edge cases around proration, retries, partial failures, usage metering, and financial consistency.
What your design needs to cover
Subscription lifecycle
Recurring charges
Proration on plan changes
Seat-based billing
Usage-based (metered) billing
Invoicing
Key challenges the editorial covers
Learn from other designs
Concepts used in this design
The building blocks this design relies on, each explained in its own lesson.
Related problems
Design a Cloud Based Data Backup Solution (advanced)
Design a Task Scheduler (medium)
Design a Cloud Storage Gateway (advanced)