Design a Shared User Quota Authority
Let concurrent services consume one user's hard quota without overspending or charging a retry twice.
Problem statement
For this exercise, assume several authenticated services consume a shared per-user budget of integer units. Each service knows an operation's positive cost before starting work. An accepted consume decision spends that cost immediately; a rejection spends nothing. Every user has one immutable limit for each UTC day.
The sum of accepted costs for a user and day must never exceed that limit, even under concurrent callers or failover.
A consume request carries a stable request ID, the user, the intended day and the cost. Identical retries recover the same decision; reuse with different inputs is a conflict. The authority decides which day is open. A new request cannot spend a closed or future day's budget.
A retry may recover its earlier closed-day receipt but cannot charge the next day. Keep receipts for 30 days; reject unsupported older retries rather than guess them as new work. Clients may inspect the authoritative remaining amount and recover an uncertain decision.
While authority is unavailable, return an explicit unavailable or unknown outcome and do not grant speculative credit.
Design admission, state ownership, horizontal scaling, retries, daily rollover and failure recovery. Business execution after admission, refunds, variable-cost reservations, billing and cross-region active-active writes are outside scope.
The report names shared user quota, strong consistency, high concurrency and no overspending; the daily period, known-cost interface and detailed lifecycle are bounded practice assumptions completing a compiled topic reference, not evidence of another independent interview.
This practice exercise is based on an interview-preparation compilation, not an independently dated interview occurrence.
What to build
- A service obtains one authoritative allow or reject decision for a known cost shared across all services for that user and day.
- A caller recovers an identical decision after a lost response without a second charge, and conflicting request-ID reuse is rejected.
- Clients inspect remaining budget, while a new UTC day opens a separate budget without changing earlier receipts or decisions.
At scale
- For this exercise, assume one million active users and20,000 consume commands per second in one region; one hot user may reach1,000 commands per second.
- For this exercise, target50 ms p95 decision latency in healthy operation and preserve every acknowledged decision through one availability-zone failure.
- For this exercise, retain decision receipts for 30 days and make hard no-overspend correctness more important than admitting work during an authority partition.