Black Friday: 30% off every plan through November 30. See the prices
SysDesignPrep.com
Study guide

Updated 24 October 2026

Subscriptions and recurring billing

Designing SaaS and consumer subscription billing: plans, prices and entitlements, billing cycles and invoices, proration on upgrades and downgrades, usage-based billing and metering, payment retries and dunning, trials, cancellations, taxes, and keeping billing and access in sync.

Reading is half of it. Now try it in an interview.An AI interviewer asks you to design a Payment System, out loud or typed, and scores the answer for your level. Or watch a sample interview first, free with no sign-up to start.
Start an AI mock

Charging a card once is a payment problem. Charging the right amount every month, through plan changes, failed cards, trials, usage spikes and cancellations, while making sure access matches what the customer paid for, is a billing system. Subscription products (SaaS, streaming, AI APIs) depend on it, and interviewers use it to test state machines, scheduling, idempotency and money correctness together.

The core model

EntityHolds
Product and planwhat is sold and its features
Priceamount, currency, interval (monthly, yearly), or usage-based tiers; versioned, never edited in place
Customerbilling details, payment methods, tax information
Subscriptioncustomer, price(s), status, current period start and end, trial and cancellation settings
Invoicethe amount due for a period, with line items
Paymentattempts to collect an invoice
Entitlementwhat the customer may use right now

Prices are immutable versions: changing a price creates a new one, and existing subscriptions keep theirs unless migrated deliberately.

Subscription lifecycle

A state machine, for example: trialing to active; active to past_due when payment fails; past_due back to active on successful retry or to canceled or unpaid after the dunning period; active to canceled at period end if the customer cancels. Persist states and transitions, and drive side effects (emails, access changes) from transition events. See event-driven architecture.

Billing cycles

At each period boundary:

  1. A scheduled job finds subscriptions whose period ends (bucketed by time, run continuously rather than all at midnight). See delayed jobs and distributed cron.
  2. It creates an invoice for the next period (and usage for the last), with line items, discounts and tax.
  3. It attempts payment with the default payment method, using an idempotency key derived from the invoice id so retries never double charge. See idempotency keys in practice.
  4. It advances the subscription period.

Each step must be safe to rerun; the job will crash at some point mid-run.

Proration

When a customer upgrades mid-cycle, charge for the remaining time at the new price and credit the unused time at the old price. Downgrades are often applied at the next renewal to avoid refunds. Represent prorations as explicit invoice line items so customers can see them, and use exact integer arithmetic in minor units. See payments and ledgers.

Usage-based billing

API calls, tokens, storage, seats: metered usage needs a pipeline:

  • Record usage events with idempotency (event ids), from services at the point of use.
  • Aggregate per customer, meter and period in a stream or batch job, deduplicating. See counting at scale.
  • Rate the totals with tiered or volume pricing at invoice time.
  • Show near-real-time usage to customers, and enforce limits or alerts on budgets.
  • Reconcile aggregates against raw events before invoicing. See data quality and data contracts.

AI APIs bill by tokens this way; see Design LLM Inference.

Failed payments and dunning

Cards expire and get declined. Dunning recovers revenue:

  • Retry on a schedule (for example after 1, 3, 5 and 7 days), at smart times, with network card updater services to refresh expired cards.
  • Email and in-app prompts to update the payment method. See sending email at scale.
  • A grace period during which access continues, then restricted access, then cancellation.

Entitlements and access

The product must answer "can this customer use feature X now?" quickly and correctly:

  • Maintain an entitlements record per customer, updated from subscription events (plan change, payment failure after grace, cancellation).
  • Services check entitlements from a cache, not by calling the billing system on every request. See caching.
  • Reconcile entitlements against subscriptions regularly so a missed event does not leave free access or block paying users.

Trials, coupons and cancellations

  • Trials with or without a card; convert automatically at the end, with reminders before.
  • Coupons as discounts with durations (once, repeating for N months, forever), applied at invoice time.
  • Cancel immediately (with optional prorated refund) or at period end; allow reactivation before the end.

Taxes and compliance

Sales tax and VAT depend on customer location and product type; use a tax service, store tax details on invoices, and keep invoices immutable once finalised (issue credit notes for corrections). Strong customer authentication rules in some regions require re-authentication for some charges.

Build or buy

Billing platforms (Stripe Billing and others) handle much of this. Interviews may still ask you to design it; in practice, the integration still needs webhooks, entitlements and reconciliation on your side. See webhooks.

In the interview

"Subscriptions are a persisted state machine; a continuous scheduler picks up subscriptions at period end, generates an invoice with prorations, usage and tax, and charges it with an invoice-derived idempotency key. Failures enter dunning with scheduled retries and emails; transitions emit events that update a cached entitlements record that services check. Usage events are deduplicated and aggregated per period, and reconciled before invoicing." See Design a Payment System.

Checklist

  • Immutable, versioned prices; explicit subscription state machine.
  • Idempotent, rerunnable billing jobs spread over time.
  • Proration as visible line items in integer minor units.
  • Metered usage with deduplication, aggregation and reconciliation.
  • Dunning with retries, card updates, grace periods and notifications.
  • Cached entitlements driven by events and reconciled.
  • Immutable invoices, credit notes and tax handling.

Questions people ask

What is a subscription billing system?

A subscription billing system charges customers the right amount every period, through plan changes, failed cards, trials, usage spikes and cancellations, and keeps their access matched to what they paid for. Its core entities are products and plans, immutable versioned prices, customers, subscriptions, invoices, payments and entitlements. Each subscription is a persisted state machine, for example moving from trialing to active, to past_due when a payment fails, and to canceled after dunning or at period end.

How does recurring billing avoid double charging customers?

Each charge carries an idempotency key derived from the invoice id, so a retried payment attempt never charges twice. At each period boundary a scheduled job creates the invoice for the next period, attempts payment with the default payment method and advances the subscription period. Every step must be safe to rerun, because the job will crash mid-run at some point, and the job runs continuously over time buckets rather than all at midnight.

How does proration work when a customer upgrades?

On a mid-cycle upgrade, proration charges for the remaining time at the new price and credits the unused time at the old price. Downgrades are often applied at the next renewal instead, to avoid refunds. Prorations should appear as explicit invoice line items so customers can see them, and be computed with exact integer arithmetic in minor units.

What is dunning in subscription billing?

Dunning is the process of recovering revenue after a subscription payment fails because a card has expired or been declined. It retries on a schedule, for example after 1, 3, 5 and 7 days, uses network card updater services to refresh expired cards, and sends email and in-app prompts asking the customer to update the payment method. Access continues through a grace period, followed by restricted access and then cancellation.

How does usage-based billing work?

Usage-based billing records usage events, such as API calls, tokens, storage or seats, with event ids at the point of use, then aggregates them per customer, meter and period in a stream or batch job, deduplicating along the way. At invoice time the totals are rated with tiered or volume pricing. Aggregates are reconciled against raw events before invoicing, and customers see near-real-time usage with limits or budget alerts. AI APIs bill by tokens this way.

How do you keep billing and feature access in sync?

Maintain an entitlements record per customer that answers whether they may use a feature right now, updated from subscription events such as a plan change, a payment failure after the grace period, or a cancellation. Services check entitlements from a cache rather than calling the billing system on every request. Entitlements are reconciled against subscriptions regularly, so a missed event neither leaves free access nor blocks paying users.