Design a Usage-Based Credit Tracking System for a SaaS Platform
Design a Usage-Based Credit Tracking System for a SaaS Platform
You are designing a credit tracking system for a B2B SaaS data-enrichment platform. Users perform "enrichments" (e.g., looking up person/company data) which consume a known number of credits. The system must accurately track each account's credit balance, deduct credits as operations are performed, prevent accounts from exceeding their available credits, and provide trustworthy usage reporting for users and finance.
Design the end-to-end system to maintain account credit balances, authorize and record credit consumption for every operation, and support the surrounding lifecycle: monthly plan refreshes, credit rollover, overage charges, and billing reconciliation.
Constraints & Assumptions:
- ~100k active accounts, ~50M credit-consuming operations/day, peaking at ~5k ops/sec. Operations can be bursty, with single batch jobs submitting tens of thousands of rows.
- Operations consume a small integer number of credits (1-50). Cost is usually known before execution, but some third-party-metered operations are only fully known after the call.
- Plans provide a monthly credit allotment (10k-1M credits) that refreshes on the account's billing anniversary. Some plans allow rollover (up to a cap), while others allow paid overage or hard-block at zero.
- Credits are treated as money: prevent accounts from going materially negative and avoid double-charging for retried operations.
- Pre-operation balance checks must be fast (single-digit milliseconds) to avoid throttling throughput.
- Usage history must be queryable for user dashboards and monthly invoices, and retained for years for audit/disputes.
AI interview prep
Core dilemma
Balancing strict transactional consistency and atomicity for credit deduction against the need for high throughput, low latency authorization checks, especially under bursty load and with potentially eventual consistency for reporting.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a Usage-Based Credit Tracking System for a SaaS Platform
Design a Usage-Based Credit Tracking System for a SaaS Platform
You are designing a credit tracking system for a B2B SaaS data-enrichment platform. Users perform "enrichments" (e.g., looking up person/company data) which consume a known number of credits. The system must accurately track each account's credit balance, deduct credits as operations are performed, prevent accounts from exceeding their available credits, and provide trustworthy usage reporting for users and finance.
Design the end-to-end system to maintain account credit balances, authorize and record credit consumption for every operation, and support the surrounding lifecycle: monthly plan refreshes, credit rollover, overage charges, and billing reconciliation.
Constraints & Assumptions:
- ~100k active accounts, ~50M credit-consuming operations/day, peaking at ~5k ops/sec. Operations can be bursty, with single batch jobs submitting tens of thousands of rows.
- Operations consume a small integer number of credits (1-50). Cost is usually known before execution, but some third-party-metered operations are only fully known after the call.
- Plans provide a monthly credit allotment (10k-1M credits) that refreshes on the account's billing anniversary. Some plans allow rollover (up to a cap), while others allow paid overage or hard-block at zero.
- Credits are treated as money: prevent accounts from going materially negative and avoid double-charging for retried operations.
- Pre-operation balance checks must be fast (single-digit milliseconds) to avoid throttling throughput.
- Usage history must be queryable for user dashboards and monthly invoices, and retained for years for audit/disputes.