feat: implement EWMA rate limiter with strategy support (#404)#476
Open
saniddhyaDubey wants to merge 1 commit intocameri:mainfrom
Open
feat: implement EWMA rate limiter with strategy support (#404)#476saniddhyaDubey wants to merge 1 commit intocameri:mainfrom
saniddhyaDubey wants to merge 1 commit intocameri:mainfrom
Conversation
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.
Description
Implements an Exponentially Weighted Moving Average (EWMA) rate limiter as the new default strategy, replacing the sliding window approach. The EWMA algorithm stores only two values per key (rate and timestamp) in a Redis hash, making it significantly more memory-efficient than the sliding window which stores every request in a sorted set. The entire EWMA calculation is handled atomically via a Lua script in Redis, preventing race conditions.
Related Issue
#404
Motivation and Context
The sliding window rate limiter stores every request timestamp in a Redis sorted set, causing memory usage to grow linearly with traffic. For high-traffic relays with thousands of concurrent clients, this becomes a primary cost driver. EWMA solves this by maintaining only two values per key regardless of traffic volume, while still accurately penalizing bursty behavior through exponential decay.
How Has This Been Tested?
calculateEWMAcovering first request, burst behavior, time decay, and long inactivity scenariosrate limitednoticerateandtimestampfields) are correctly stored and updated in Redis on each request, and confirmed rate limiting triggers under loadScreenshots (if appropriate):
End-to-end EWMA rate limiting verification:
Types of changes
Checklist: