Design Usage Metering and Billing for a Multi-Channel Token API

Last updated: November 29, 2026

Quick Overview

Design the system that counts input and output tokens for every API call, enforces prepaid credits and plan limits, produces invoices, and reconciles usage that arrives through the first-party API and through cloud marketplaces such as AWS Bedrock and Azure Foundry.

Inception
System Design
Software Engineer
Inception
November 29, 2026
Software Engineer
System Design Round
System Design
Medium

0

0

0 solved


Design the system that counts input and output tokens for every API call, enforces prepaid credits and plan limits, produces invoices, and reconciles usage that arrives through the first-party API and through cloud marketplaces such as AWS Bedrock and Azure Foundry.

Inception sells Mercury per million tokens with distinct input and output prices and offers it through its own platform and cloud marketplaces. Platform engineers have to make usage accurate to the token and resilient to retries. The interviewer checks idempotent event design, aggregation, and how billing tolerates late or duplicated data.

What the Interviewer Expects
  • Emit an immutable usage event per request with an idempotency key
  • Separate real-time balance checks from the durable billing ledger
  • Aggregate by tenant, model and price tier into hourly rollups
  • Handle partial streams, cancellations and retries without double charging
  • Reconcile marketplace-reported usage against internal records
Key Topics to Cover
Usage Metering
Idempotency
Event Streaming
Ledgers
Reconciliation
How to Approach This
  1. Start by clarifying functional and non-functional requirements with the interviewer.
  2. Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
  3. Draw a high-level architecture first, then deep dive into 1-2 critical components.
  4. Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
  5. Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
  • How do you stop a prepaid customer from going far below zero during a burst?
  • How would you apply a temporary 50% discount retroactively and auditably?
  • What changes when you add per-request pricing for fine-tuned private models?
  • How do you let customers see near-real-time usage in a dashboard?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Count prompt and completion tokens per request with model id, tenant, API key and channel. Enforce prepaid credit and plan caps in near real time. Monthly invoices with line items by model and token t...

High-Level Design

Inference workers know the exact token counts at completion and publish a usage_event (request_id as idempotency key, tenant, model, input_tokens, output_tokens, started_at, status) to a durable log...


Submit Your Answer
Markdown supported

Related Questions