Skip to content

Conversation

@JoelHJames1
Copy link

  1. IRateLimitRule Interface: Defines the contract for all rate limiting rules with the IsRequestAllowed method.
  2. RateLimiter Class: The main class that manages rate limits for different resources. It allows setting different rules for different resources and checking if requests are allowed.
  3. RequestTracker: Tracks request history for tokens and resources, providing in-memory storage.
  4. Rule Implementations:
    • RequestsPerTimespanRule: Limits the number of requests in a given timespan (e.g., 100 requests per hour)
    • TimeIntervalBetweenRequestsRule: Ensures a minimum time interval between requests (e.g., 1 second between requests)
    • RegionalRule: Applies different rules based on the token's region (US vs EU)
    • CompositeRule: Combines multiple rules using logical operators (AND/OR)
      Requirements Fulfillment

The implementation meets all the specified requirements:

  1. Restricting requests: The system can restrict the number of requests a client can make using various rule types.
  2. Configurable and extendable rules: The rules are highly configurable with parameters like maximum requests, timespan, and minimum interval. New rule types can be added by implementing the IRateLimitRule interface.
  3. Combining rules: The CompositeRule allows combining multiple rules with AND/OR operators, enabling complex rate limiting strategies.
  4. Different rule types: All required rule types are implemented, including requests per timespan, timespan between requests, and regional rules.
  5. In-memory storage: The RequestTracker provides thread-safe in-memory storage using ConcurrentDictionary.

Command to Run Tests
dotnet test RateLimiter.Tests

The project successfully implements the rate-limiting pattern with a flexible, extensible design that meets all the requirements.

@JoelHJames1 JoelHJames1 closed this Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants