Skip to content

feat: adds shared rate limiting to the relay using Redis #3796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 12, 2025

Conversation

simzzz
Copy link
Contributor

@simzzz simzzz commented May 27, 2025

Description:
This PR refactors the rate limiting logic in our JSON-RPC relay service to support both local (LRUCache) and distributed (Redis) backends. The changes include:

  • Introducing a new RateLimiterService class with a pluggable backend system.
  • Defaulting to Redis for centralized rate limiting across multiple pods, with a fallback to LRUCache if Redis is unavailable.
  • Enhancing configuration handling to support future backend extensions like Hazelcast or Memcached.
  • Implementing a "fail fast" approach by throwing a ConfigurationError if a required client is missing.
  • These improvements aim to make the rate limiting system more flexible and scalable.

Related issue(s):

Closes #3780, closes #3781, closes #3782

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@simzzz simzzz added this to the 0.69.0 milestone May 27, 2025
@simzzz simzzz self-assigned this May 27, 2025
@simzzz simzzz added the enhancement New feature or request label May 27, 2025
@lfdt-bot
Copy link

lfdt-bot commented May 27, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Copy link

github-actions bot commented May 27, 2025

Test Results

 22 files  ±  0  289 suites   - 6   21m 26s ⏱️ - 16m 31s
664 tests + 15  657 ✅ + 14  5 💤 ±0  2 ❌ +1 
868 runs  +123  859 ✅ +122  7 💤 +2  2 ❌  - 1 

For more details on these failures, see this check.

Results for commit ff30194. ± Comparison against base commit d45744b.

This pull request removes 5 and adds 20 tests. Note that renamed tests count towards both.
Should reset limit for requests ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Rate Limit Tests Should reset limit for requests
Should submit batch requests to WS server and receive IPRateLimitExceeded error until rate limit is reached ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Rate Limit Tests Should submit batch requests to WS server and receive IPRateLimitExceeded error until rate limit is reached
Should submit single requests to WS server and receive IPRateLimitExceeded error until rate limit is reached ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Rate Limit Tests Should submit single requests to WS server and receive IPRateLimitExceeded error until rate limit is reached
should not throw rate limit exceeded error for eth_chainId ‑ RPC Server Acceptance Tests Acceptance tests @ratelimiter Rate Limiters Acceptance Tests RPC Rate Limiter Acceptance Tests Given requests within the Tier 2 rate limit should not throw rate limit exceeded error for eth_chainId
should throw rate limit exceeded error for eth_chainId ‑ RPC Server Acceptance Tests Acceptance tests @ratelimiter Rate Limiters Acceptance Tests RPC Rate Limiter Acceptance Tests Given requests exceeding the Tier 2 rate limit should throw rate limit exceeded error for eth_chainId
should distribute WebSocket requests across services without interference ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Shared Rate Limiting Acceptance Tests Shared WebSocket Rate Limiting Between Services should distribute WebSocket requests across services without interference
should distribute requests across services without interference ‑ RPC Server Acceptance Tests Acceptance tests @ratelimiter Shared Rate Limiting Acceptance Tests Shared Rate Limiting Between Services should distribute requests across services without interference
should handle concurrent WebSocket requests from both services ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Shared Rate Limiting Acceptance Tests WebSocket Service Independence and Failover should handle concurrent WebSocket requests from both services
should handle concurrent requests from both services ‑ RPC Server Acceptance Tests Acceptance tests @ratelimiter Shared Rate Limiting Acceptance Tests Service Independence and Failover should handle concurrent requests from both services
should handle mixed single and batch requests across WebSocket services ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Shared Rate Limiting Acceptance Tests WebSocket-Specific Rate Limiting Scenarios should handle mixed single and batch requests across WebSocket services
should immediately rate limit on serviceB after serviceA hits the limit ‑ RPC Server Acceptance Tests Acceptance tests @ratelimiter Shared Rate Limiting Acceptance Tests Shared Rate Limiting Between Services should immediately rate limit on serviceB after serviceA hits the limit
should immediately rate limit on wsServiceB after wsServiceA hits the limit ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Shared Rate Limiting Acceptance Tests Shared WebSocket Rate Limiting Between Services should immediately rate limit on wsServiceB after wsServiceA hits the limit
should maintain independent Redis connections for WebSocket services ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Shared Rate Limiting Acceptance Tests WebSocket Service Independence and Failover should maintain independent Redis connections for WebSocket services
should maintain independent Redis connections ‑ RPC Server Acceptance Tests Acceptance tests @ratelimiter Shared Rate Limiting Acceptance Tests Service Independence and Failover should maintain independent Redis connections
should maintain rate limiting consistency during WebSocket connection handoffs ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-ratelimiter Shared Rate Limiting Acceptance Tests WebSocket-Specific Rate Limiting Scenarios should maintain rate limiting consistency during WebSocket connection handoffs
…

♻️ This comment has been updated with latest results.

simzzz added 9 commits May 28, 2025 14:22
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
@simzzz simzzz force-pushed the 3512-shared-rate-limitin branch from ab78839 to 5aca99e Compare May 28, 2025 11:24
@simzzz simzzz marked this pull request as ready for review May 29, 2025 07:17
@simzzz simzzz requested review from a team as code owners May 29, 2025 07:17
simzzz added 3 commits May 29, 2025 16:55
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
@simzzz simzzz changed the title feat: shared rate limiting feat: adds shared rate limiting to the relay using Redis May 29, 2025
Copy link
Contributor

@konstantinabl konstantinabl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes needed

Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
@simzzz simzzz requested a review from konstantinabl June 5, 2025 13:17
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work as always and appricate the efforts.

simzzz added 2 commits June 6, 2025 14:25
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
@simzzz simzzz requested a review from quiet-node June 6, 2025 12:11
simzzz added 2 commits June 6, 2025 15:11
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
@simzzz simzzz requested a review from quiet-node June 10, 2025 11:06
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice I think it looks good just one item.

simzzz and others added 2 commits June 11, 2025 10:57
Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
@konstantinabl konstantinabl requested a review from quiet-node June 11, 2025 10:51
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM great work!

@simzzz simzzz merged commit 6b670fc into main Jun 12, 2025
44 of 46 checks passed
@simzzz simzzz deleted the 3512-shared-rate-limitin branch June 12, 2025 12:11
mwb-al pushed a commit to mwb-al/hiero-json-rpc-relay that referenced this pull request Jun 23, 2025
…r#3796)

Signed-off-by: Simeon Nakov <simeon.nakov@limechain.tech>
Co-authored-by: konstantinabl <konstantina.blajukova@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants