Skip to main content

Subscription & Billing Systems: Recurring Revenue Management

00:04:01:59

The Subscription Economy

Subscription-based businesses have become the dominant model for SaaS platforms. Building a robust subscription system requires careful consideration of billing cycles, plan management, payment handling, and customer experience.

Core Components

Subscription Lifecycle

Understanding the subscription lifecycle is fundamental:

  1. Trial: Free or discounted period
  2. Active: Regular billing cycle
  3. Past Due: Payment failed, grace period
  4. Canceled: Subscription ended
  5. Expired: Trial or subscription expired

Database Schema

A well-designed schema supports complex scenarios:

sql
CREATE TABLE subscriptions (
  id UUID PRIMARY KEY,
  user_id UUID NOT NULL,
  plan_id UUID NOT NULL,
  status VARCHAR(50) NOT NULL,
  current_period_start TIMESTAMP,
  current_period_end TIMESTAMP,
  cancel_at_period_end BOOLEAN DEFAULT FALSE,
  canceled_at TIMESTAMP,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE invoices (
  id UUID PRIMARY KEY,
  subscription_id UUID NOT NULL,
  amount DECIMAL(10,2) NOT NULL,
  status VARCHAR(50) NOT NULL,
  due_date TIMESTAMP,
  paid_at TIMESTAMP,
  created_at TIMESTAMP DEFAULT NOW()
);

Billing Cycle Management

Recurring Billing

Implementing recurring billing:

  1. Schedule jobs: Cron or task queue for billing
  2. Calculate amount: Based on plan and usage
  3. Create invoice: Generate invoice record
  4. Charge payment method: Process payment
  5. Update subscription: Extend period on success
  6. Handle failures: Enter dunning process

Proration

Handling plan changes fairly:

  • Upgrades: Prorate difference, immediate access
  • Downgrades: Prorate credit, change at period end
  • Add-ons: Prorate from addition date
  • Cancellations: Refund unused portion (if policy allows)

Invoice Generation

Invoice Structure

Every invoice should include:

  • Invoice number: Unique, sequential identifier
  • Billing period: Start and end dates
  • Line items: Detailed breakdown
  • Subtotal, tax, total: Clear pricing
  • Payment method: How customer paid
  • Due date: When payment is due

PDF Generation

Generate professional invoices:

  • Use libraries like pdfkit or puppeteer
  • Include company branding
  • Make invoices downloadable
  • Email invoices automatically
  • Store invoices for record-keeping

Dunning Management

Payment Failure Handling

When payments fail:

  1. Immediate notification: Email customer about failure
  2. Retry schedule: Automated retry attempts
  3. Grace period: Allow time to update payment method
  4. Service degradation: Limit access if needed
  5. Final cancellation: Cancel after all retries fail

Retry Strategy

Typical retry schedule:

  • Day 1: First retry attempt
  • Day 3: Second retry attempt
  • Day 7: Third retry attempt
  • Day 14: Final retry attempt
  • Day 15: Cancel subscription

Communication

Keep customers informed:

  • Payment failure emails: Clear, actionable messages
  • Retry notifications: Inform before retrying
  • Success confirmations: Confirm when payment succeeds
  • Cancellation notices: Final warning before cancellation

Plan Management

Plan Types

Common plan structures:

  • Fixed plans: Set price, set features
  • Usage-based: Pay for what you use
  • Hybrid: Base price + usage charges
  • Tiered: Different prices for different usage levels

Plan Changes

Handle plan changes smoothly:

  • Immediate upgrades: Grant access immediately
  • Scheduled downgrades: Change at period end
  • Proration calculations: Fair pricing adjustments
  • Feature access: Update permissions correctly

Usage Tracking

Metered Billing

For usage-based pricing:

  • Track usage: API calls, storage, transactions
  • Aggregate data: Sum usage per billing period
  • Calculate charges: Apply pricing tiers
  • Bill accurately: Include in next invoice

Implementation

javascript
// Track usage
await trackUsage(userId, 'api_calls', 100);

// Calculate bill
const usage = await getUsageForPeriod(userId, periodStart, periodEnd);
const charges = calculateCharges(usage, plan);

Tax Handling

Tax Calculation

Tax is complex but necessary:

  • Determine taxability: Based on location and product
  • Calculate tax: Use tax services or tables
  • Display clearly: Show tax separately
  • File returns: Comply with tax requirements

Tax Services

Consider using services like:

  • Stripe Tax: Automatic tax calculation
  • Avalara: Comprehensive tax solution
  • TaxJar: Sales tax automation

Reporting & Analytics

Key Metrics

Track important subscription metrics:

  • MRR (Monthly Recurring Revenue): Predictable revenue
  • Churn rate: Customer retention
  • LTV (Lifetime Value): Customer value
  • CAC (Customer Acquisition Cost): Acquisition efficiency
  • ARPU (Average Revenue Per User): Revenue per customer

Dashboards

Build dashboards showing:

  • Revenue trends: Growth over time
  • Churn analysis: Why customers leave
  • Plan distribution: Popular plans
  • Payment success rates: Billing health

Real-World Example

For a SaaS platform, I built:

  • Multi-tier plans: Free, Pro, Enterprise
  • Usage-based add-ons: API calls, storage
  • Annual discounts: 20% off annual plans
  • Trial periods: 14-day free trials
  • Dunning management: 4-retry payment process
  • Invoice system: PDF generation and email delivery
  • Analytics dashboard: Real-time subscription metrics

Results:

  • 95% payment success rate (after dunning)
  • 30% annual plan adoption (higher LTV)
  • 5% monthly churn rate (industry-leading)
  • Automated 99% of billing (minimal manual intervention)

Best Practices

  1. Automate everything: Manual billing doesn't scale
  2. Handle edge cases: Plan changes, prorations, cancellations
  3. Communicate clearly: Keep customers informed
  4. Test thoroughly: Billing bugs are expensive
  5. Monitor metrics: Track subscription health
  6. Document processes: Complex logic needs documentation
  7. Comply with regulations: Tax, refund policies, etc.

Building a subscription system is complex, but the recurring revenue model makes it worthwhile. The key is automating as much as possible while maintaining flexibility for edge cases and providing excellent customer experience throughout the subscription lifecycle.