Configuration: Service Module ‐ Rate Limiter - ChrisMavrommatis/Binacle.Net GitHub Wiki

When the Service Module is enabled, rate limiting is applied to the calculation endpoints. The rate limiter is preconfigured with default settings, but you can adjust these to fit your specific requirements.

Below is an example of the default configuration found in the RateLimiter.json file:

{
  "RateLimiter": {
    "Anonymous" : "SlidingWindow::10/60-10"
  }
}

This rate limiter applies globally to anonymous users. For instance, with the default configuration of 10 requests per minute, all anonymous users collectively can only make 10 requests per minute, not per individual user.

Configuration

The rate limiter configuration follows the format:

{RateLimiterType}::{RateLimiterConfiguration}

Each rate limiter type has its own configuration format, as outlined below.

Supported Rate Limiter Types

Fixed Window

The Fixed Window rate limiter enforces a hard limit on the number of requests that can be made within a fixed time window. It applies a constant rate limit regardless of when the requests occur within the window.

Configuration Format:

{Number of requests}/{Time in seconds}

Example

FixedWindow::10/60
  • FixedWindow: Uses the fixed window strategy.
  • 10: Allows 10 requests during the time window.
  • 60: Time window lasts 60 seconds (1 minute).

This means a maximum of 10 requests can be made every 60 seconds, and the counter resets at the end of each period.

Sliding Window

The Sliding Window rate limiter provides a more adaptive approach by dividing the time window into smaller segments. This smoother traffic handling reduces sudden bursts or idle periods, ensuring a more consistent request flow.

Configuration Format:

{Number of requests}/{Time in seconds}-{Number of segments}

Example

SlidingWindow::100/30-3
  • SlidingWindow: Uses the sliding window strategy.
  • 100: Allows 100 requests during the full time window.
  • 30: Time window lasts 30 seconds.
  • 3: The window is divided into 3 segments.

In this configuration, the time window is divided into 3 segments. Requests processed in expired segments are recycled back into the current segment, leading to a more even distribution of requests over time.

Customizing the Rate Limiter

To customize the rate limiter settings, you can do it either via:

  1. Configuration File: Edit the RateLimiter.json file.
  2. Environment Variables: Set the RateLimiter__Anonymous environment variable. This will override the RateLimiter.json file.

[!Warning]

If both the configuration file and environment variables are set, the environment variables will take precedence.

Conclusion

This concludes the overview of the rate limiter configuration. Tailor these settings to suit the needs of your deployment, ensuring optimal performance and resource protection.