Usage Metering & Billing Pipeline  ·  View 11 of 22  ·  Data

Data Model

Ten entities, and the provenance field that makes a disputed line answerable.

Editable source SVG draw.io All views
account account_id PK plan_version_id FK billing_currency billing_cycle cycle_anchor_day meter meter_id PK name type counter|gauge|hwm|unique period_grain dimension_keys plan_version plan_version_id PK plan_id effective_from effective_to pricing_shape immutable true restatement restatement_id PK scope acct|meter|period reason authorised_by original_amount restated_amount usage_event event_id PK (producer) account_id FK meter_id FK quantity event_ts / ingest_ts dimensions map schema_version aggregate account_id FK meter_id FK dimension_hash period_start / grain quantity event_range provenance state prov|closed priced_line line_id PK invoice_id FK plan_version_id FK quantity tier_breakdown amount fx_rate_date invoice invoice_id PK account_id FK period status draft|issued subtotal / credits amount_payable issued_at balance_entry entry_id PK account_id FK grant_id delta cause created_at credit_memo memo_id PK invoice_id FK reason authorised_by amount 1 : N 1 : N N : 1 1 : N 1 : N N : 1 1 : N 1 : N 1 : N Data Model — Event to Invoice Line event_range on aggregate is the provenance that lets one invoice line be expanded back to its events. The dashed relation is the credit drawdown, which only exists where a grant applies. v 1.0 · owner Architecture Practice · date 2026-10

Decisions

  • event_id is producer-assigned and is the primary key, which puts the idempotency boundary at the producer. The alternative — a server-side content fingerprint — is question 1 of the requirement and is unresolved; this model takes the producer side.
  • aggregate carries event_range, the provenance that lets one invoice line be expanded back to its constituent events. Without it the evidence path in view 15 cannot exist.
  • priced_line carries plan_version_id and fx_rate_date rather than a copy of the price, so re-rating a historical period reproduces the original amount exactly.
  • restatement is an entity, not a log line: it holds the scope, the authorising identity and both figures.

Assumptions

  • Both event_ts and ingest_ts are retained on every event, so clock skew is visible rather than silently trusted.
  • dimensions is an open map; pricing may depend on any key in it, which is what lets a new dimensioned meter ship as configuration.

Risks

  • An open dimension map is an open cardinality risk: a producer that puts a request id in it will make the aggregate grain per-event, and the cost-per-meter signal is the only thing that will notice.
  • The dashed credit drawdown relation is where double-spend lives if balance entries are not written under the same transaction as the line that consumed them.