System Design Atlas

Subscription billing, usage and service entitlements

05 / 10Worked example

Authoritative data and states

What results arise from the two possible orders of usage ingestion and period finalisation?

The interfaces require an authoritative state. Each usage event takes effect at most once. R-161 contains exactly the usage included at finalisation, priced using T-2. Late events do not overwrite a finalised invoice, and an unknown payment outcome is not treated as a definite rejection. The table separates current states from the evidence that established them.

Starting point Compare the event identifier and the 100 units together.

Assumptions for the example case

Original fictional example design: one monthly contract in EUR, positive integer usage units, a fixed tariff version per period, one invoice and one payment order, and separate correction records. Figures and quality targets are illustrative test assumptions. Tax law, multiple currencies, prorated tariff changes and debt collection are outside the scope.

Data relationships and permitted transitions

Finalised usage snapshot and separate correction

V-161 · T-21,000 + 2 cents/unit
Period P-10Watermark
N-161100 units
R-1611,200 cents
Z-161Payment instruction
periode_offen → abschluss_läuft → abgerechnetabgerechnet → zahlung_offen → bezahlt / abgelehntLate usage → correction record

V-161 and T-2 define P-10; R-161 holds the finalised snapshot; late N-161 links to a separate correction record.

Usage arrives while an invoice is being generated. Fix an unambiguous ingestion watermark. Either order leads to billing through the invoice or a separate correction record.

Entities and relationships

EntityAuthoritative dataResponsibility
Contract V-161Customers, tariff T-2, entitlement ruleThe tariff version applies to the fixed period.
Usage event N-161Event identification, time of event, unitsAssigned to one period exactly once.
Period P-10Half-open time window and finalisation watermarkSeparates accepted usage from later corrections.
Invoice R-1611,000 cents base price plus 200 cents usage, in EURImmutable once finalised.
Payment order Z-161Invoice, 1200 cents, resultAn unknown outcome remains open.
Service entitlementContract, state, reason and validity periodFollows an explicit rule, rather than reacting directly to every transport message.

Contract V-161

Authoritative data
Customers, tariff T-2, entitlement rule
Responsibility
The tariff version applies to the fixed period.

Usage event N-161

Authoritative data
Event identification, time of event, units
Responsibility
Assigned to one period exactly once.

Period P-10

Authoritative data
Half-open time window and finalisation watermark
Responsibility
Separates accepted usage from later corrections.

Invoice R-161

Authoritative data
1,000 cents base price plus 200 cents usage, in EUR
Responsibility
Immutable once finalised.

Payment order Z-161

Authoritative data
Invoice, 1200 cents, result
Responsibility
An unknown outcome remains open.

Service entitlement

Authoritative data
Contract, state, reason and validity period
Responsibility
Follows an explicit rule, rather than reacting directly to every transport message.

Permitted state transitions

Starting pointTargetCondition
periode_offenabschluss_läuftThe ingestion boundary is recorded atomically.
abschluss_läuftabgerechnetR-161 is generated from exactly the usage included at finalisation.
abgerechnetzahlung_offenZ-161 has been durably created.
zahlung_offenbezahltMatching payment evidence is available.
zahlung_offenzahlung_abgelehntA definite rejection is evidenced.
zahlung_abgelehntanspruch_eingeschränktAgreed grace period ends; customer service sees the reason.
bezahlt or anspruch_eingeschränktterminal_für_periodeLate usage produces a correction record; the next period is a separate entity.

periode_offen

Target
abschluss_läuft
Condition
The ingestion boundary is recorded atomically.

abschluss_läuft

Target
abgerechnet
Condition
R-161 is generated from exactly the usage included at finalisation.

abgerechnet

Target
zahlung_offen
Condition
Z-161 has been durably created.

zahlung_offen

Target
bezahlt
Condition
Matching payment evidence is available.

zahlung_offen

Target
zahlung_abgelehnt
Condition
A definite rejection is evidenced.

zahlung_abgelehnt

Target
anspruch_eingeschränkt
Condition
Agreed grace period ends; customer service sees the reason.

bezahlt or anspruch_eingeschränkt

Target
terminal_für_periode
Condition
Late usage produces a correction record; the next period is a separate entity.

Set an atomic finalisation boundary

Set an atomic finalisation boundary

Fix an unambiguous ingestion watermark.

Usage arrives during invoice generation.

Either ordering bills the usage through the invoice or a separate correction record.

Alternative considered
A running sum query can include an inconsistent subset of usage.
Trade-off
Late usage requires follow-up processing.
Reassess
A different billing cutoff is agreed.

Terms in this step

Set an atomic finalisation boundary
Either ordering bills the usage through the invoice or a separate correction record.

Try it yourself

Execute N-161 ingestion and period finalisation in both commit orders. State the invoice amount and any correction.

A hint for your attempt

Use the specific entities and conditions from this step. The two solution parts distinguish the decision from its evidenced outcome.

Compare with a possible solution
First part of the solution
Ingestion wins: R-161 totals 1,200 cents with no additional 200-cent correction.
Second part of the solution
Finalisation wins: R-161 stays at 1,000 cents; review produces a separate 200-cent correction record. The 100 units are billed once overall.

Apply to your project

Which corresponding assumption in your project would you check first when a different billing cutoff is agreed?

Step 6 examines how to decouple billing and payment.