Smooth Weighted Round Robin Across LLM Provider Targets
Last updated: November 29, 2026
Quick Overview
Implement a router that spreads requests across model provider targets in proportion to configured integer weights, interleaving picks smoothly instead of sending bursts, and skipping targets marked unhealthy.
Truefoundry
November 29, 20260
0
0 solved
Implement a router that spreads requests across model provider targets in proportion to configured integer weights, interleaving picks smoothly instead of sending bursts, and skipping targets marked unhealthy.
An AI gateway like TrueFoundry's lets a team define a virtual model that splits traffic, for example 80/20 between two deployments of the same model. The interviewer checks whether you can produce an exact weighted split that does not hammer one target with consecutive requests, and whether health changes are handled cleanly.
What the Interviewer Expects
- Produce picks whose long-run frequencies match the weights exactly
- Avoid bursts: a weight 5 target should not get 5 picks in a row when others exist
- Skip unhealthy or zero-weight targets without breaking the ratio among the rest
- O(n) per pick in the number of targets with O(n) state
- Explain why random weighted choice is not good enough for small windows
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
- How would you make this safe when many gateway replicas route concurrently?
- How do you add latency-aware weighting on top of static weights?
- What happens to the sequence when a weight is changed at runtime?
- How would you support sticky routing for a user session?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a map of target name to positive integer weight. pick() returns the next target. Over any cycle of length equal to the total weight, each target appears exactly weight times, and picks are ...
High-Level Design
Use the smooth weighted round robin scheme (the one nginx popularized). Each target keeps a current score. On every pick, add each live target's weight to its score, choose the highest score, then s...