Subscription Billing Architecture: How Recurring Commerce Payments Work
How to architect subscription billing for ecommerce: plans and prices, the subscription state machine, schedules, invoices, proration, tax, credits, payment collection, events, order creation and testing.
Quick answer
Subscription billing architecture separates four concerns. A catalog defines plans, prices and intervals. A subscription store holds each subscription's state and schedule. A billing engine decides what is owed when the schedule fires: it creates an invoice with lines, discounts, proration, tax and credits. A payment service collects the invoice, retries failures and emits events that move the subscription between states and create orders for shipments. Make every step idempotent, keep the invoice as the record, and test with simulated time.
Where This Fits
This is the engine room behind subscription ecommerce development. The card payment layer (stored credentials, merchant-initiated renewals, dunning) is in ecommerce recurring payments, and the customer controls built on top are in subscription management portal. Platform-specific setup is in Shopify subscription store.
The Components
| Component | Responsibility | Key design point |
|---|---|---|
| Catalog | Plans, prices, intervals, add-ons, trial rules | Version prices; never edit a price existing subscribers depend on |
| Subscription store | State, items, quantities, address, schedule | Explicit state machine with allowed transitions |
| Scheduler | Finds subscriptions due for billing | Safe to rerun; one invoice per period |
| Billing engine | Creates invoices with lines, proration, discounts, credits | Deterministic and auditable |
| Tax step | Calculates tax on each invoice | Uses the address and product tax codes at billing time |
| Payment service | Charges, retries, refunds | Idempotency keys from the invoice |
| Events | Notifies orders, fulfilment, CRM, finance | At-least-once delivery, idempotent consumers |
The Subscription State Machine
Write down the states and transitions before choosing tools. Ambiguous states cause the worst billing bugs: a 'cancelled' subscription that still renews, or a 'paused' one that still ships.
trialing -> active (trial ends, first invoice paid)
trialing -> cancelled (customer cancels during trial)
active -> past_due (renewal payment failed)
past_due -> active (retry or updated card succeeds)
past_due -> paused|cancelled (grace period ends, per policy)
active -> paused (customer pauses; no invoices while paused)
paused -> active (resume date reached or customer resumes)
active -> cancelled (immediately, or at period end)
cancelled -> active (reactivation creates a new period)Billing Schedules
Each subscription has an anchor date and an interval. The scheduler finds subscriptions whose next billing date has arrived and asks the billing engine to create the invoice. Handle month-end anchors (a subscription started on the 31st), time zones (bill in a consistent zone and show dates in the customer's), skips (move the next date without changing the anchor) and shipment-based schedules where billing happens a set number of days before fulfilment.
Invoices
Even when customers only see a receipt, the system needs an invoice record: subscription, period, line items, discounts, proration, credits, tax and total, plus status (draft, open, paid, failed, void). Payments, refunds and disputes reference the invoice. Finance uses invoices for revenue and tax reporting, and support uses them to explain charges.
Changes and Proration
Customers change plans, quantities, frequency and addresses. Decide for each change whether it applies now with proration, at the next renewal, or to the next shipment. Software-style subscriptions usually prorate; physical product subscriptions usually apply changes to the next shipment, because goods already shipped cannot be partly reversed. Billing platforms document their proration behaviour, for example Stripe's proration options, and your choice should be explained in plain language wherever the customer makes the change.
Discounts, Credits and Trials
Model discounts with their duration (first order, a number of cycles, forever) so they expire automatically. Keep credits as balances applied to future invoices, with a ledger of how they were earned and used. Trials need clear conversion rules: when the first charge happens, what amount and what reminder the customer receives beforehand.
Outgrowing your subscription app's billing logic?
ZSpace Labs can map your subscription states, schedules and invoices, and build or integrate a billing layer that your OMS, payments and finance tools can rely on.
Tax on Recurring Invoices
Calculate tax on each invoice at billing time, using the current shipping address and product tax codes, because rates and addresses change between renewals. Store the calculated tax on the invoice. Price changes in tax-inclusive markets need care to avoid charging customers more than they agreed. See tax integration.
Payment Collection and Retries
The payment service charges the stored credential as a merchant-initiated transaction with an idempotency key derived from the invoice, and the webhook confirms the outcome. Failures move the subscription to past due and start dunning. Those details are in recurring payments, and decline classification is in payment failure handling.
Events, Orders and Integrations
Emit events for state changes and invoice outcomes: invoice paid, payment failed, subscription paused, cancelled, reactivated. Consumers create orders for paid renewals, update CRM and email tools, adjust demand forecasts and post revenue to finance. Consumers must be idempotent because events can arrive twice. See event-driven architecture and webhooks.
Testing With Simulated Time
- Trials converting, with and without a payment method
- Renewals at month end, leap years and time-zone boundaries
- Upgrades, downgrades, quantity changes and frequency changes mid-cycle
- Pauses, skips and resumes
- Failed payments, retries, recovery and cancellation for non-payment
- Discounts expiring after the right number of cycles
- Scheduler reruns that must not create duplicate invoices
Build, Buy or Use the Platform
Platform subscription features and apps cover most ecommerce needs. Billing platforms suit complex pricing, usage-based charges and multiple channels. Building is justified only for unusual models with a team to maintain it, because billing logic accumulates edge cases. Whatever you choose, keep your own record of subscriptions and invoices accessible to the rest of your stack.
Trade-offs in Billing Design
Billing on a fixed calendar date is easy to understand but bunches load and renewals; anniversary billing spreads load but makes proration and reporting harder. Prorating every change is precise but confusing for physical goods; applying changes at the next cycle is simpler but can feel slow to customers who upgrade. Generating invoices a few days before charging gives time for tax calculation, reminders and stock planning, but adds a state to manage. Centralizing billing in one platform simplifies operations but makes it a single point of failure. None of these is wrong; the mistake is leaving them implicit.
How to Design Subscription Billing Step by Step
- 1. Define plans, prices and intervals with versioning
- 2. Draw the state machine and agree it with operations and support
- 3. Choose schedule rules: anchors, month ends, time zones, skips and billing lead time
- 4. Decide change policies: proration or next-cycle, per change type
- 5. Design the invoice model with lines, discounts, credits and tax
- 6. Connect payment collection using recurring payment patterns
- 7. Emit events and build idempotent consumers for orders, CRM and finance
- 8. Build customer controls in the subscription portal
- 9. Test with simulated time before launch and after every billing change
Worked Example
An illustrative scenario, not a client case: a pet food subscription occasionally double-ships after its nightly job is rerun following a server restart. The team adds a unique invoice key per subscription and period, derives payment idempotency keys from invoices, and creates orders only from 'invoice paid' events processed idempotently. Reruns become harmless, and support can now see exactly which invoice produced which shipment.
Common Mistakes
- No explicit state machine
- Editing prices that existing subscribers depend on
- Schedulers that create duplicate invoices on rerun
- Orders created before payment confirmation
- Proration rules nobody can explain to customers
- Testing only in real time
Need billing you can trust at every renewal?
Talk to ZSpace Labs about subscription billing architecture, Shopify subscription builds and billing operations automation.
Conclusion
Subscription billing is a set of small, explicit systems: catalog, states, schedules, invoices, tax, payments and events. Make each idempotent and auditable, and test with simulated time. Related: recurring payments, subscription portal and subscription retention.
Common questions
The design of the systems that decide what each subscriber owes and when: plans and prices, subscription states and schedules, invoice generation, proration, tax, credits and the handoff to payment collection and order creation.