Skip to content

[monetization] Track durable usage-based billing and plan consistency #1511

Description

@kang-heewon

Priority

P0 umbrella — establish the trusted monetization path before adding a Croco-owned rating engine, credit ledger, or additional billing providers.

Context

This plan is based on trunk at 2a6e12c5c214eaa817046ebcf6b477796131609f.

Croco already has strong local domain building blocks:

  • @croco/metering-core records usage, enforces quota, and supports idempotency;
  • @croco/billing-core owns checkout, subscription lifecycle, plan lookup, proration seams, and invoice types;
  • @croco/entitlements-core enforces feature and metered quota access;
  • @croco/billing-polar owns the current production billing provider boundary;
  • the SaaS preset and admin surfaces already connect or display parts of this state.

The missing path is the boundary between locally observed usage and provider-accepted billable usage. Today a usage record can be persisted and a UsageRecordedEvent can be published, but the framework does not define a durable provider-delivery contract, provider usage capability, immutable plan-version binding, or a build-time consistency check tying meters, plan pricing, subscriptions, and entitlements together.

Goal

A Croco application should be able to:

  1. define a typed meter once;
  2. record billable usage with a stable logical event identity;
  3. durably deliver that usage to a billing provider without silent loss or duplicate charging;
  4. pin each subscription to an immutable plan version;
  5. ensure the same plan version owns provider product mappings and entitlement/quota rules;
  6. detect unsupported or incomplete monetization wiring before deployment;
  7. prove the full path through conformance and generated SaaS evidence.

Design principles

  • Local usage, durable billable intent, and provider-accepted usage are separate states.
  • Request handlers must not synchronously depend on a remote billing provider.
  • Provider retries must be idempotent; duplicate acknowledgement is success, not failure.
  • Provider capabilities must be explicit and inspectable, not optional methods with permissive fallbacks.
  • Published plan versions are immutable and subscriptions remain pinned until explicitly migrated.
  • Entitlement and provider pricing mappings must resolve from the same plan version.
  • Reuse ContractGraph, Problem Registry, events/transaction boundaries, diagnostics, provider certification, and generated-app smoke rather than adding another control plane.
  • Keep provider-rated billing as the first supported path. A Croco-owned rating engine is deferred until provider limitations justify a second source of truth.

Delivery order

Foundation

  • Typed billable meter definitions and usage envelopes
  • Durable billable usage journal and delivery state
  • Explicit usage-billing provider capabilities
  • Idempotent Polar usage event delivery

Product consistency

  • Immutable plan versions pinned to subscriptions
  • Plan-version-bound entitlement sets
  • Monetization edges and diagnostics in ContractGraph

Executable evidence

  • Usage-billing provider conformance suite
  • Generated SaaS metered-overage golden path

Child issue links will be added after creation.

Foundation exit gate

Do not add a public internal rating engine until all of the following are true:

  • A billable usage event survives process/provider failure after local commit.
  • Replaying the same logical event cannot increase provider usage twice.
  • Permanent provider rejection is visible and cannot be reported as successful delivery.
  • A subscription resolves one immutable plan version and its provider mappings.
  • Entitlement quota and overage policy resolve from that same version.
  • An unbound billable meter or unsupported provider capability fails verification.
  • The generated SaaS scenario proves provider outage, replay, duplicate acknowledgement, and final usage consistency without live credentials by default.

Explicit non-goals

  • Building a general billing control plane or hosted billing service.
  • Replacing Polar invoice calculation, tax, payment collection, or dunning.
  • Supporting arbitrary JavaScript pricing callbacks.
  • Implementing a local promotional credit ledger in this phase.
  • Reopening completed admin panel or generic SaaS smoke work; this initiative should extend those existing surfaces when its read models are available.

Existing related work

This initiative must build on those outcomes rather than duplicate them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureArchitecture and module boundary issuesfeatureProduct feature or roadmap capability

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions