Weighted Fair Request Scheduler Across API Organizations
Last updated: November 29, 2026
Quick Overview
Implement a scheduler that queues inference requests per organization, each with a token cost, and dequeues them so that over time each organization receives throughput proportional to its weight, using deficit round robin.
Anthropic
November 29, 20260
0
0 solved
Implement a scheduler that queues inference requests per organization, each with a token cost, and dequeues them so that over time each organization receives throughput proportional to its weight, using deficit round robin.
When Claude API capacity is constrained, one heavy customer must not starve others, and a fair scheduler in front of the inference fleet is one way to enforce that. Anthropic onsite rounds often build such a component in stages, and the interviewer checks a correct deficit round robin, handling of variable request cost, and clean state transitions when queues empty and refill.
What the Interviewer Expects
- Explains why plain round robin is unfair when request costs vary
- Implements deficit round robin with a per-organization quantum scaled by weight
- Grants the quantum once per turn and keeps leftover deficit only while the org has work
- Resets deficit when a queue empties so idle orgs cannot bank credit
- Analyzes the cost when one request is much larger than the quantum
- Writes a test showing a 2:1 weight produces a 2:1 service ratio
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- A single request costs 100x the quantum. How do you avoid spinning many empty rounds before serving it?
- How would you add priority tiers (for example, interactive versus batch) on top of fairness?
- Costs are estimated from max_tokens but the true output length is known only afterward. How do you correct the deficit?
- How would you make this scheduler work across several gateway replicas?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
add_org(org, weight), enqueue(org, req_id, cost), dequeue() -> (org, req_id) or None. Within an org, FIFO. Across orgs, long-run token throughput proportional to weight among orgs that have pend...
High-Level Design
Per-org FIFO queues plus a deque of active orgs in service order. Each org has a deficit counter. When an org reaches the head for a new turn, it gains quantum * weight. While its head request fits ...