System Design Atlas

Subscription billing, usage and service entitlements

10 / 10Worked example

Design and evidence

Which tests verify that usage is billed once and unconfirmed collections are handled correctly?

The final design reuses the complete runtime topology from step 6. Test markers connect key decisions to expected results and earlier steps to revisit. The following items form a test plan; measured evidence is still outstanding.

Starting point Restrict entitlements only after the agreed grace period.

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.

Overall architecture with evidence

Runtime architecture · Ingestion, period finalisation and payment inbox

  1. 1 · Ingest usage
  2. 2 · Fix the watermark
  3. 3 · Track payment
  4. 4 · Explain entitlement
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
Watermark · Step 3/5Replay · Step 4Payment status · Step 7/9

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.

Test plan with review loops

ValidationExpected resultReturn to an earlier step
Concurrency in both ordersPeriod finalisation and N-161 compete. Ingestion wins: R-161 totals 1,200 cents. Finalisation wins: R-161 totals 1,000 cents, and N-161 produces a separate 200-cent correction record after review. In either order, the 100 units are billed only once overall.Steps 3 and 5
Identical and changed retriesSend N-161 with 100 units twice: the result is 100 units. Reusing its identifier with 101 units produces a conflict. Sending Z-161 twice with identical content uses the same 1,200-cent payment collection; changing the amount is forbidden.Step 4
Exact value or time limitUsage at 31 October 23:59:59.999 UTC belongs to P-10; usage at 1 November 00:00:00.000 UTC belongs to the next period. Zero or negative units are rejected; corrections have their own record type.Steps 2 and 5
Lost response and restartThe payment service collects payment for R-161, but its response is lost. Billing operations queries Z-161. This unknown outcome does not restrict the entitlement as a definite rejection would; a late confirmation completes the same payment order.Steps 7 and 9

Concurrency in both orders

Expected result
Period finalisation and N-161 compete. Ingestion wins: R-161 totals 1,200 cents. Finalisation wins: R-161 totals 1,000 cents, and N-161 produces a separate 200-cent correction record after review. In either order, the 100 units are billed only once overall.
Return to an earlier step
Steps 3 and 5

Identical and changed retries

Expected result
Send N-161 with 100 units twice: the result is 100 units. Reusing its identifier with 101 units produces a conflict. Sending Z-161 twice with identical content uses the same 1,200-cent payment collection; changing the amount is forbidden.
Return to an earlier step
Step 4

Exact value or time limit

Expected result
Usage at 31 October 23:59:59.999 UTC belongs to P-10; usage at 1 November 00:00:00.000 UTC belongs to the next period. Zero or negative units are rejected; corrections have their own record type.
Return to an earlier step
Steps 2 and 5

Lost response and restart

Expected result
The payment service collects payment for R-161, but its response is lost. Billing operations queries Z-161. This unknown outcome does not restrict the entitlement as a definite rejection would; a late confirmation completes the same payment order.
Return to an earlier step
Steps 7 and 9

First end-to-end validation

End-to-end path
Test N-161 before and after finalisation, and Z-161 with a lost response. The 100 units take effect once and the invoice remains immutable.
Open decision
Tariff changes and partial payments are subsequent extensions. Tax law, multiple currencies, prorated tariff changes and debt collection require a separate follow-up design.

Test late usage

Test late usage

Test N-161 before and after finalisation, and Z-161 with a lost response.

The race with finalisation determines which usage the invoice includes.

The 100 units are billed once and the invoice remains immutable.

Alternative considered
A normal monthly run does not test races at the finalisation boundary.
Trade-off
Tests need control over the finalisation commit.
Reassess
After that, tariff changes and partial payments are added.

Terms in this step

Test late usage
The 100 units are billed once and the invoice remains immutable.

Try it yourself

For late usage and a lost payment-collection response, name a test, expected result and step to revisit.

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
Race N-161 against finalisation in both orders: bill 200 cents of usage once overall and preserve the finalised invoice. A failure leads back to step 5.
Second part of the solution
Lose the response for Z-161: exactly one collection occurs and uncertainty alone does not block the entitlement. A failure leads back to steps 7 and 9.

Apply to your project

Which corresponding assumption in your project would you check first before adding tariff changes and partial payments?

Transfer the system boundary, evidence and open decisions to the editable Markdown design template.

Start your own design

Choose a small case from your project. The template collects the ten design tasks and leaves space for your sketches, decisions, and open assumptions. You can edit it in your text editor or note-taking app.

Download design template (.md)
Compare the ten tasks with the example case
  1. Purpose and boundary

    Which corresponding assumption in your project would you check first when new grace-period or goodwill policies are introduced?

    In the example: Model service entitlements with a reason and validity period. Customers see an explained service commitment.

  2. Requirements

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

    In the example: Separate positive usage from correction records. N-161 remains one uniquely identified event.

  3. Scale estimates

    Which corresponding assumption in your project would you check first when the contract count or finalisation window changes?

    In the example: Use 27.78 invoices/s as a separate test profile. Daily usage and month-end finalisation impose different loads.

  4. Interfaces

    Which corresponding assumption in your project would you check first when new sources have different event contracts?

    In the example: Compare the event identifier and the 100 units together. A retry still represents 100 units.

  5. Data and states

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

    In the example: Fix an unambiguous ingestion watermark. Either ordering places the usage on the invoice or on a separate correction document.

  6. Overall architecture

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

    In the example: Finalise invoices immutably and track payments separately. Payment failures do not alter invoice content.

  7. Critical flow

    Which corresponding assumption in your project would you check first when provider reconciliation becomes unreliable?

    In the example: Query the same Z-161. A timeout creates neither a new charge nor a definitive rejection.

  8. Bottlenecks and trade-offs

    Which corresponding assumption in your project would you check first when tariff calculations become more complex?

    In the example: Measure tariff calculations, locks and the payment queue separately. Expand capacity only at the actual bottleneck.

  9. Operations and security

    Which corresponding assumption in your project would you check first when the product team changes its goodwill terms?

    In the example: Restrict entitlements only after the agreed grace period. Customer service can explain the reason and date.

  10. Final design

    Which corresponding assumption in your project would you check first before adding tariff changes and partial payments?

    In the example: Test N-161 before and after finalisation, and Z-161 with a lost response. The 100 units take effect once and the invoice remains immutable.