Per Token Usage Metering Pipeline For Inference Billing
Last updated: November 29, 2026
Quick Overview
Design the system that records prompt and completion tokens for every inference request across all GPU replicas and turns them into accurate customer invoices, usage dashboards and spend limits.
Fireworks AI
November 29, 20260
0
0 solved
Design the system that records prompt and completion tokens for every inference request across all GPU replicas and turns them into accurate customer invoices, usage dashboards and spend limits.
Fireworks charges per token for serverless models and per GPU hour for dedicated deployments, so billing correctness is a revenue and trust issue. The interviewer is checking exactly-once accounting reasoning, aggregation design and how near-real-time spend caps work.
What the Interviewer Expects
- Emit usage events at the replica with an idempotency key
- Use a durable log and idempotent aggregation to avoid double billing
- Separate a fast approximate path for limits from an exact path for invoices
- Handle streams that are cancelled or fail midway
- Support different price units (per token, per GPU second, cached tokens)
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How would you bill a stream the client disconnected from halfway?
- How do you reprice usage if a price change was applied late?
- How would you enforce a hard monthly spend cap within a few seconds of breach?
- How do you reconcile replica-side counts with gateway-side counts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Record per request: account, API key, model, prompt tokens, cached prompt tokens, completion tokens, timestamps, status. Invoices must be exact and auditable; dashboards can lag a minute; spend caps s...
High-Level Design
Replicas finish a request and emit a usage event keyed by request id into a local buffer, flushed to a partitioned log (Kafka) keyed by account. A stream processor aggregates per account, model and mi...