fix(round_robin): randomize starting index to distribute load across targets#13
Merged
Conversation
…targets - Round robin strategy now picks a random starting target on first use, then rotates deterministically. This ensures that new limiter instances (created per-request) distribute load evenly instead of always starting at target[0], which made round_robin behave like first_available. - Add tests for sequential rotation, concurrent rotation, and distribution across multiple instances.
jlenon7
approved these changes
Apr 23, 2026
jlenon7
left a comment
Member
There was a problem hiding this comment.
lgtm, but take a look at the suggestion
Co-authored-by: João Lenon <lenonSec7@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
round_robinbehave identically tofirst_availableContext
When consumers create a new
RateLimiterinstance per request (e.g. the socials API),rrIndexalways started at0. Every request would hit target[0] first, makinground_robinindistinguishable fromfirst_available.The fix initializes
rrIndexto a random value on first use (rrIndex: number | null = null), so each instance starts at a different target. After that, rotation proceeds deterministically.