Group
  • Payments

    Implement usage-based (metered) billing correctly

    Reports usage to the provider reliably, with local records that survive retries and idempotent submission.

    • Improve quality
    • Automate workflows
    • Advanced
    • General

Free Prompt

Audit my usage-based billing implementation (or build it if I'm launching usage pricing). Usage billing fails quietly: unreported usage is money left on the table, double-reported usage is overcharging customers. Implement: record usage events locally first (a durable usage table in my own database, written in the same transaction as the action being billed, so billing can't be lost if the provider call fails); report to the provider from the local records with idempotency (the provider's usage records accept idempotency keys or idempotent-set semantics; retries after a timeout must not double-count); a reconciliation path comparing local usage totals against what the provider billed each cycle; aggregation done correctly (sum at report time from local records rather than incrementing a remote counter, so corrections and replays stay possible); and a deliberate policy for the end-of-cycle boundary (usage at 23:59:59 on the last day: which invoice does it land on, and is the answer the same every time). Don't report usage fire-and-forget at action time without a local record; a failed API call then loses revenue invisibly. Don't let clients report their own usage; usage records come from server-side actions only. Deliver: the usage recording, the reporting job with idempotency, the reconciliation, and verification: generate usage in test mode, kill the reporting mid-flight, and confirm recovery reports exactly once with correct totals.

What This Does / How This Helps

Makes usage billing trustworthy in both directions: durable local records so no billable action is lost, and idempotent reporting so retries never double-charge. Metered billing is the model where bugs bill themselves in both directions. Fire-and-forget reporting loses revenue silently every time the API hiccups. Naive retries overcharge customers. And without a local record, there's no way to prove what a customer actually used when they dispute the invoice. The kill-and-recover verification is the honest test: interrupt the reporting pipeline and confirm it resumes without losing or duplicating a single unit.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts