HLDArena
HLD-211·Messaging & Queues
Medium · 1,000 pts

SaaS Usage-Based API Metering & Spend Aggregator

Design a high-throughput usage metering pipeline counting billable API tokens and compute units per tenant while serving real-time billing dashboard queries.

Max p99
≤ 60 ms
Availability
≥ 99.5%
Budget
≤ $5,100

Functional Requirements

  • FR-1POST /usage/events — Ingests idempotent usage records keyed by tenant_id and request_id.
  • FR-2GET /usage/{tenant_id} — Returns current billing-period consumption and spend alerts.
  • FR-3PATCH & DELETE /usage/events/{tenant_id} — Updates, revokes, or deletes tenant_id entries with bounded TTL or explicit cache/index invalidation.
  • FR-4Must buffer heavy batch inference bursts and isolate 6x storage compaction brownouts.

Workload Profile

Baseline Metering22,000 Read RPS / 14,000 Event Write RPS
Batch Inference Surge70,000 Read RPS / 38,000 Write RPS
Active Working Set24 GB rolling billing-period counters & dedup keys
Traffic DistributionSkewed consumption on large enterprise tenant_id accounts

Consistency Model

Bounded eventual dashboard rollup (< 5s) acceptable; billable usage events must never be dropped.

Design Write-up
0 boxes · 0 edges
0 words
Hidden Cases #4–#7 run automatically on Submit
Case 1: Smoke & API ContractInput Workload
Read RPS
2,000 rps
Write RPS
400 rps
Key Distribution
Uniform (Low Skew)
Chaos Fault
None (Healthy Cluster)
Expected Pass CriteriaASSERTIONS
• Tail Latency: p99 ≤ 120 ms
• Availability: ≥ 99.5%
Valid end-to-end Client → Compute → Storage topology