System Design Atlas

Subscription billing, usage and service entitlements

06 / 10Worked example

The overall architecture

Which invoice data remain unchangeable despite subsequent tariff changes?

The data contract defines the runtime topology: usage source → ingestion API → usage and contract store. The finalisation worker fixes the period watermark and writes invoices. The payment worker reads payment orders and sends them to the payment service; results enter a durable inbox. The entitlement service reads evidenced contract and payment decisions. The customer portal reads invoices and entitlements through separately authorised views. Internal modules define domain boundaries in code; a separate process has its own operational lifecycle.

Starting point Fix an unambiguous ingestion watermark.

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.

Runtime architecture

Runtime architecture · Ingestion, period finalisation and payment inbox

Usage sourcePositive units
Customer portalInvoice + entitlement

Billing platform

Ingestion APIIdentity + time + units
Usage and contract storeV-161 · P-10 · T-2 · R-161 · Inbox table
Finalisation workerWatermark + invoice
Payment workerDeliver Z-161
Payment ingestionCheck source, order and amount
Entitlement serviceEvidenced decision
Payment serviceCollect payment
Usage source → Ingestion APIN-161
Ingestion API → Usage and contract storeEvent + T-2
Usage and contract store → Finalisation workerPeriod watermark
Finalisation worker → Usage and contract storeR-161 + Z-161
Usage and contract store → Payment workerZ-161
Payment worker → Payment serviceImmutable collection request
Payment service → Payment ingestionAuthenticated payment evidence
Payment ingestion → Usage and contract storeDeduplicate and commit inbox entry
Usage and contract store → Entitlement serviceEvidenced payment outcome
Usage and contract store → Entitlement serviceContract + invoice
Customer portal → Entitlement serviceAuthorised view
Entitlement service → Customer portalInvoice + entitlement

Ingestion maintains usage and tariff data; the finalisation worker fixes R-161; payment evidence reaches the entitlement service through the durable inbox.

Payment collection may complete minutes later. Finalise the invoice immutably and track payment separately. Payment failures leave invoice content unchanged.

Domain modules within the application

Inside the billing process · Five domain modules

Usage ingestionIdentity + time + positive units
Tariff bindingT-2 per period
Period finalisationUnambiguous watermark
Payment reconciliationTrack Z-161
Entitlements and correctionsReason + record

Usage ingestion and tariff binding produce an unambiguous finalisation. Payment reconciliation and entitlement handling keep unknown outcomes and corrections visible.

Usage ingestion checks identity, time and positive units. Tariff binding fixes the agreed price version per period. Period finalisation closes a precisely defined set of usage events. Payment reconciliation tracks the existing collection. Entitlements and corrections provides reasons for restrictions and separate correction records.

Operational boundaries

Runtime
Usage source → ingestion API → usage and contract store. The finalisation worker fixes the period watermark and writes invoices. The payment worker reads payment orders and sends them to the payment service; results enter a durable inbox. The entitlement service reads evidenced contract and payment decisions. The customer portal reads invoices and entitlements through separately authorised views.
Persistence
Transactional store for contract V-161, usage event N-161 and period P-10. The authoritative business change and its retry result are saved together; external side effects require separate evidence.

Decouple billing and payment

Decouple billing and payment

Finalise invoices immutably and track payments separately.

Payment collection may complete minutes later.

Payment errors do not change invoice content.

Alternative considered
Rebuilding the invoice for every payment attempt can change the amount.
Trade-off
Several distinct states must be displayed.
Reassess
Partial payments are added to the scope.

Terms in this step

Decouple billing and payment
Payment errors do not change invoice content.

Try it yourself

Payment collection fails after the tariff has changed. Which data in R-161 may change?

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
R-161 retains tariff T-2 and its finalised usage snapshot unchanged.
Second part of the solution
The payment receives the evidenced failure status. A new payment attempt or follow-up process must not recalculate the invoice using the current tariff.

Apply to your project

Which corresponding assumption in your project would you check first when partial payments are added to the scope?

Step 7 examines how to resolve an uncertain payment collection.