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.
Course outline (16 lessons)
Before this lesson:Invoice and Payment Lifecycle in Accounting SoftwareAccrual vs Cash Accounting
In this lesson · 5 sections
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.
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 fornew_plan_remaining − unused_credit, credit that upgrade invoice toUnearned Revenue, mark unposted old schedule linessuperseded, 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(orCashif refunded) for the unused balance.
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.
| Account | Debit (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.
| Account | Debit (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.
| Account | Debit (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:
| Account | Debit (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 scheduledDr Unearned Revenue / Cr Subscription Revenueentries each period. - Use integer remainder allocation or cumulative day-based rounding so schedule lines always sum to
total_minorwith 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.
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.
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.
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
Connected lessons
Educational content only—not accounting, tax, legal or investment advice. See our editorial policy or report an error via our corrections policy.