feat(throttle): allow customized rate limiter#7405
Open
dentiny wants to merge 1 commit into
Open
Conversation
tisonkun
reviewed
May 2, 2026
Member
tisonkun
left a comment
There was a problem hiding this comment.
I'm considering that this might make the throttle layer configuration too complex and overly generalized. I’ve been thinking about how much code can actually be reused here and to what extent it should depend on governor.
Since there seems to be very little reusable code, I think two other approaches might be more appropriate:
- Let users who want a custom rate limiter write their own layer from scratch. Currently, this throttle layer is heavily dependent on
governor's functionality. - Follow the pattern used in observability: write a layer-throttle-base and then provide the specific implementations out of the box.
If we stick with the current approach in this PR, where we depend on governor while trying to allow custom rate limits, there isn't much reusable throttle code anyway. Instead, it just makes the codebase far too generalized.
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.
Rationale for this change
Hi team, for rate limit there're two metrics I care about (1) what's the blocking wait time; (2) what's the queue depth; these two metrics are important to provide insight on user workload.
I raise a related feature request here: #7312, but requires more change.
A way to unblock me for now is to allow customized rate limiter, similar to what we do at
ConcurrentLimitLayer.What changes are included in this PR?
This PR makes rate limiter generic so users could provide their own implementation; it should be a no-op change.
Are there any user-facing changes?
Current implementation
SharedRateLimiteris used as default generic argument, so no API change.AI Usage Statement
I get opus 4.6 implement the feature, with concurrent limit layer as a reference.