Skip to Content
All Systems

04RevenueType: Reference architecture

Billing that refuses to guess

A Zoho CRM design for recurring, one-off and usage-based services that bills only what was delivered and measured, after two separate human acts.

Shows

  • Business Automation
  • Software Architecture
  • API Design

Where this comes from: Drawn from systems I've designed on Zoho. The business, names and data here are generalized. The patterns and failure modes come from real work, and the design includes what that work taught me.

On This Page

In 30 Seconds

Every month, a mix of recurring, one-off and usage-based services has to become correct invoices. In this architecture, each sold product becomes one permanent service line in Zoho CRM, and billing reads nothing else. A line is billed only once its delivery is recorded and its amount is known. The system prepares each month, people approve it and close it, and only a closed month can reach the e-invoicing provider.

What It Guarantees

  • Nothing is billed before it is delivered.
  • Unknown usage is never billed as zero.
  • Preparing the same month again adds no second bill.
  • Nothing irreversible happens without two separate human acts: approving the orders, then closing the month.
  • An issued document is never edited. A new document corrects it.

The Problem

Picture a services company that sells to small businesses. Each customer signs a yearly contract that mixes a monthly subscription, a one-off setup service and a charge based on usage. Sales closes the contract the day it is signed. Delivery starts weeks later. Usage figures arrive from another system after the month ends.

A common setup bills from the contract. The first invoice goes out from the signature date, before anything was delivered. The monthly job runs before the usage data lands, so usage goes out at zero. When an invoice is wrong, someone edits it.

Under many national e-invoicing systems, an issued invoice is registered with the tax authority and can only be corrected by a credit note. Every mistake becomes a conversation with the customer. The quiet failure costs more: a line the job skipped is revenue nobody misses, because nothing says it was due.

The Approach, in One Sentence

Bill only service lines that are delivered and measured, and issue a document only after people approve the bills and close the month.

Architecture

From sold product to an invoice that never changes
Service lineOne per sold product; price and terms frozen
Delivery recordOwner, dates, status and reason for any delay
Billing startLater of service start and delivery month
Prepare the monthOne draft order per customer per month
ValidateBlockers and warnings, named per customer
Approve ordersStep one: zero blockers, who and when
Close the monthStep two: recorded with a snapshot of findings
Dispatch gateChecks durable job log, provider switch, closed month
E-invoicing providerDuplicate key required; live issuing needs a code change
Issued documentNo status field; legal number arrives on success
CorrectionA credit note that points to the original

Connections in this diagram

  • Service line → Delivery record (if delivery needed)
  • Delivery record → Billing start (completion stamps month)
  • Billing start → Prepare the month (due lines only)
  • Prepare the month → Validate (unknown usage refused)
  • Validate → Approve orders (person)
  • Approve orders → Close the month (separate act)
  • Close the month → Dispatch gate (closed months only)
  • Dispatch gate → E-invoicing provider (sent once)
  • E-invoicing provider → Issued document (on success)
  • Issued document → Correction (never edited)

Live invariant checks run against the data at every stage.

Key Decisions

  1. Delivery is a record, not a checkbox

    No billing before delivery is the business rule. The mechanism that enforces it is the design. Alternatives: bill from the signature date, or tick a "delivered" box, which can't say who is late. I chose a delivery record with an owner, dates and a reason for any delay. Completion stamps the month the work belongs to, and billing starts at the later of the service start and that month. Contract dates are never rewritten.

  2. Unknown is a refusal, not a zero

    Alternatives: bill zero and fix it later, or estimate. A usage line with no usage record is refused by name, and the gap blocks approval of the month. A customer who used nothing has a record that says zero, and that line passes. "I don't know" and "it's zero" are different answers, and the difference is money.

  3. Two separate acts, at the level of the month

    Alternatives: one "prepare and send" button, or an approval per invoice. One button turns every wrong click into a credit note. Approval per invoice adds friction to a bulk task, and friction gets bypassed. So a person approves the orders, refused for the whole batch if any order is blocked. The cost is deliberate: one blocked customer holds the month until the line is fixed, or excluded with a written reason. Then a person closes the month, recorded with what the checks showed. The dispatch service itself refuses any order from an open month. A gate that lives only on a screen is a suggestion.

  4. The order and the document are two records

    Alternatives: one invoice record with a status field, or issuing through the accounting system. People edit the order until approval. The issued document is a separate record with no status field. It exists only after the provider confirms success, which also brings its legal number. The call is guarded in code: drafts only, a required duplicate-protection key, and a provider switch that is off by default. Drafts only is the safe default while the system is built and tested. Issuing for real takes a code change, because a setting can be flipped by mistake, while a code change is deliberate, reviewed and leaves a trace.

When Things Go Wrong

  • A job reruns, or someone presses Prepare again

    → Orders carry a customer:month key in a unique field; order lines carry line:month. The second run adds nothing.

  • Two overlapping runs write the same record

    → In my tests, the platform's unique check stopped back-to-back repeats but let parallel writes through. That may have changed. Writers that create service lines share one queue outside the CRM anyway. Orders rely on their key, and a live check looks for duplicate keys.

  • Delivery is completed after its month closed

    → Completion rolls to the next open month. If none is open, the line stays unbillable and the screen says why.

  • The provider call times out

    → The outcome is unknown, so the system never resends on its own. The call's duplicate-protection key lets the provider recognize a repeat, and a lookup by that key settles what happened.

  • A line is flagged as billed with no bill behind it

    → The flag is meant only for lines that got an order line. Each flag is read back after the write, and a live check lists usage lines flagged without one.

What the Business Gets

  • Customers are billed for what they received, from the month they received it.
  • Revenue that was due but not billed appears as a named list with a reason, not as a silent gap.
  • Mistakes are caught while they are still drafts. After issue, every correction is a traceable credit note.
  • Every irreversible step carries a name and a time: who approved, who closed the month, and what they saw.

For Engineers

How I Build Systems Like This

I write the design first: the data model, the states, and each decision with the options I rejected. AI agents (Claude Code) then do much of my hands-on build work from it, code and tests included, under written rules: confirm which environment before any write, never call the invoicing provider, and never close a business or architecture decision alone.

How I Build With AI

06Revenue

One item, one committed deal

One-of-a-kind stock: every deal names one item, the item alone decides availability, and a deposit commits it to one deal.

On LinkedIn: more notes on Zoho architecture and AI.