Skip to content
AccountancyPath

Accounting for DevelopersModule 4: Production financial systemsAdvanced3 min read

Subscription Billing and Revenue Recognition Schedules

Turn SaaS subscription invoices into deferred revenue schedules in code: daily and monthly waterfalls, mid-cycle upgrades, credit notes and exact penny allocation.

Lesson 11 of 16
Course outline (16 lessons)

Before this lesson:Invoice and Payment Lifecycle in Accounting SoftwareAccrual vs Cash Accounting

When a customer pays $1,000 on 1 January for an annual SaaS plan, your bank account rises by $1,000—but your January revenue is not $1,000. Under accrual accounting, you owe the customer 12 months of software, so you park the cash in Unearned Revenue (a liability) and release a slice into Revenue each month as you deliver the service.

The deferred revenue waterfall model

A billing system separates invoicing (when cash is billed) from recognition (when service is earned) using two tables tied to journal_entries:

CREATE TABLE revenue_schedules (
  id                uuid PRIMARY KEY,
  entity_id         uuid NOT NULL,
  invoice_line_id   uuid NOT NULL,
  currency          char(3) NOT NULL,
  total_minor       bigint NOT NULL CHECK (total_minor > 0),
  service_start     date NOT NULL,
  service_end       date NOT NULL,
  method            text NOT NULL CHECK (method IN ('even_monthly', 'daily_prorata')),
  status            text NOT NULL DEFAULT 'active' -- 'active', 'superseded', 'completed'
);

CREATE TABLE revenue_schedule_lines (
  id                uuid PRIMARY KEY,
  schedule_id       uuid NOT NULL REFERENCES revenue_schedules(id),
  period_start      date NOT NULL,
  period_end        date NOT NULL,
  amount_minor      bigint NOT NULL CHECK (amount_minor > 0),
  journal_entry_id  uuid REFERENCES journal_entries(id), -- NULL until posted
  UNIQUE (schedule_id, period_end)
);

At each month-end, a scheduled job selects unposted lines where period_end <= :run_date, posts Dr Unearned Revenue / Cr Subscription Revenue using the deterministic idempotency key revrec:${scheduleId}:${periodEnd}, and links journal_entry_id in the same transaction.

Formula · Deferred revenue roll-forward

Ending unearned = Opening unearned + New billings − Revenue recognised − Credit notes

New billings
subscription invoices credited to Unearned Revenue during the period
Revenue recognised
scheduled slices moved from Unearned Revenue to Revenue
Credit notes
cancellations or downgrades reducing remaining unrecognised liability

Exact penny allocation (remainder handling)

Dividing $1,000.00 (100000 cents) by 12 months gives 8333.333... cents. If you simply round every month to 8333, 12 months total $999.96—leaving $0.04 stuck in Unearned Revenue forever.

Allocate the integer remainder deterministically in BigInt:

function splitEvenly(totalMinor: bigint, periods: number): bigint[] {
  const n = BigInt(periods);
  const base = totalMinor / n;
  const remainder = totalMinor % n; // 0 <= remainder < n
  return Array.from({ length: periods }, (_, i) =>
    BigInt(i) < remainder ? base + 1n : base,
  );
}

// Daily pro-rata using cumulative rounding so SUM(slices) === totalMinor
function splitByDays(totalMinor: bigint, periodDays: number[]): bigint[] {
  const totalDays = BigInt(periodDays.reduce((s, d) => s + d, 0));
  let cumDays = 0n;
  let allocated = 0n;
  return periodDays.map((d) => {
    cumDays += BigInt(d);
    const targetCum = (totalMinor * cumDays * 2n + totalDays) / (totalDays * 2n);
    const slice = targetCum - allocated;
    allocated = targetCum;
    return slice;
  });
}

Both helpers guarantee slices.reduce((a, b) => a + b, 0n) === totalMinor to the exact minor unit—even across leap years or awkward proration dates.

Handling upgrades, proration and cancellations

Subscriptions rarely sit still for 12 months. Keep already-posted lines immutable and adjust only the future:

  • Mid-cycle upgrade: calculate unused value left in Unearned Revenue, bill the customer for new_plan_remaining − unused_credit, credit that upgrade invoice to Unearned Revenue, mark unposted old schedule lines superseded, and generate new future lines for the combined remaining liability.
  • Cancellation with credit note / refund: cancel unposted future schedule lines and post Dr Unearned Revenue / Cr Accounts Receivable (or Cash if refunded) for the unused balance.
Worked example

CloudFern Analytics (fictional) — annual plan with penny split and April upgrade

1. 1 January — Annual Pro plan billed & paid ($1,000.00): splitEvenly(100000n, 12) schedules 4 months at $83.34 (Jan–Apr) and 8 months at $83.33 (May–Dec). Check: 4 × $83.34 + 8 × $83.33 = $333.36 + $666.64 = $1,000.00.

1 January: Collect upfront annual payment
AccountDebit (Dr)Credit (Cr)
Cash$1,000
Unearned Revenue$1,000
Total✓ Balanced$1,000$1,000

2. 31 January, 28 February, 31 March — Monthly recognition: Each month posts $83.34. After 3 months, recognised revenue is 3 × $83.34 = $250.02, leaving $1,000.00 − $250.02 = $749.98 in Unearned Revenue.

31 January: Month 1 revenue recognition
AccountDebit (Dr)Credit (Cr)
Unearned Revenue$83.34
Subscription Revenue$83.34
Total✓ Balanced$83.34$83.34

3. 1 April — Upgrade to Enterprise ($200/month) for remaining 9 months ($1,800.00): CloudFern applies the $749.98 unused Pro balance and invoices the prorated difference: $1,800.00 − $749.98 = $1,050.02.

1 April: Prorated upgrade invoice
AccountDebit (Dr)Credit (Cr)
Accounts Receivable$1,050.02
Unearned Revenue$1,050.02
Total✓ Balanced$1,050.02$1,050.02

Unearned Revenue is now $749.98 + $1,050.02 = $1,800.00. Unposted Pro lines (Apr–Dec) are superseded and replaced with 9 Enterprise lines of $200.00:

30 April: Month 4 Enterprise recognition
AccountDebit (Dr)Credit (Cr)
Unearned Revenue$200
Subscription Revenue$200
Total✓ Balanced$200$200

Explore how billing timing shifts revenue waterfalls interactively in the Revenue Recognition Lab.

Real-world application

SaaS billing engines like Stripe Billing, Chargebee and in-house ERP subledgers run automated monthly revenue waterfalls so finance can produce a deferred revenue roll-forward table for investors and auditors. Because every schedule line points directly to a journal_entry_id, finance can click any number on the income statement and trace it down to the exact customer contract and service dates.

Recap

  • Record upfront subscription billings to Unearned Revenue, then post scheduled Dr Unearned Revenue / Cr Subscription Revenue entries each period.
  • Use integer remainder allocation or cumulative day-based rounding so schedule lines always sum to total_minor with zero penny drift.
  • Handle mid-cycle upgrades and cancellations prospectively by superseding only unposted future lines and adjusting remaining Unearned Revenue.
  • Protect recognition jobs with deterministic idempotency keys (revrec:${scheduleId}:${periodEnd}).

Try it yourself

Active recall

Quick check · Test yourself

Work out each answer in your head first, then reveal the explanation and mark whether you got it right.

  1. 1A SaaS plan costs $1,000.00 (100,000 cents) for 12 equal months. How should integer penny allocation split the schedule so no cents are lost?

    Show worked answer

    Integer division gives 100,000 ÷ 12 = 8,333 cents base with a remainder of 4 cents. Allocating 1 extra cent to each of the first 4 months gives four months of $83.34 (33,336 cents) and eight months of $83.33 (66,664 cents), summing to exactly $1,000.00.

  2. 2After recognising 3 months ($250.02) of a $1,000.00 annual plan, the customer upgrades to a $200/month plan for the remaining 9 months ($1,800.00). What prorated amount is billed and what happens to Unearned Revenue?

    Show worked answer

    Remaining Unearned Revenue is $1,000.00 − $250.02 = $749.98. The prorated upgrade invoice is $1,800.00 − $749.98 = $1,050.02, which credits Unearned Revenue so the liability becomes $1,800.00—recognised at $200.00/month over the final 9 months.

  3. 3Why should a mid-year cancellation never edit January's already-posted revenue recognition entry?

    Show worked answer

    January's service was already delivered and the period may be locked. Instead, issue a credit note or refund against the remaining unrecognised Unearned Revenue and void only future unposted schedule lines.

Key terms in this lesson

Lesson 11 of 16 · Accounting for Developers

Finished this lesson?

Mark it complete to track your progress through the course. Progress is saved in this browser only.

Previous lesson: Building a Bank Reconciliation Engine

Subject GuideAccounting Systems & Personal Finance

Mei-Ling Chen(陈美玲)

Turns accounting invariants into clean code—and everyday personal money clarity.

  • Double-Entry Ledger Engineering
  • SQL Schemas & Financial APIs
  • Multi-Currency & Billing Code

More lessons with Mei-Ling

Published:

Educational content only—not accounting, tax, legal or investment advice. See our editorial policy or report an error via our corrections policy.

Search