Business processes / 5 / 12
Subscription billing
A SaaS product sells monthly plans and charges cards every night. Two runs of the job charge the same customer twice, cards get declined, customers upgrade mid-month, months have different lengths and the provider reports results later by webhook. Each problem has a concrete fix that keeps money correct and customers on board.
- 14 min
- Intermediate
- 11 steps
- Double charges
- 0 /day
- Unpaid invoices
- 0 $
- Recovered after decline
- 0 %
- Involuntary churn
- 0 %
- request
- reply
- redelivery
- duplicate
- lost
Numbers are a model scenario, not measurements
The real request
Billing API → Invoices DBRequest
invoices: new row
{
"invoice_id": "in_7001",
"subscription_id": 1"sub_42",
"plan": 2"basic_monthly",
"amount_minor": 32000,
"currency": "USD",
"period_start": 4"2026-11-01T00:00:00Z",
"period_end": 5"2026-12-01T00:00:00Z",
"status": 6"open"
}
subscription_id— The long-lived contract. Invoices come and go, the subscription stays.plan— What is sold and at what price. A price change means a new plan version, not an edit.amount_minor— Integer cents:2000= $20.00.period_start— Periods are half-open: start included, end excluded.period_end— The next period starts exactly here. No gaps, no overlaps.status—openuntil paid, thenpaid; orvoid,uncollectible.
Build it yourselfCheat sheetCompare lessons
Course: 74 lessons
01 Foundations
02 Scaling
03 Data & storage
04 Communication
05 Reliability
06 Architecture
07 Security
08 Shipping
09 Whole systems
10 Business processes
11 Case studies