Rate Limiter
A Rate Limiter is a middleware component designed to control the flow of incoming requests to a system. It ensures the system isn't overwhelmed by traffic spikes or abusive usage patterns, maintaining optimal performance and reliability.
                 +-------------------+
                 | Incoming Request  |
                 +-------------------+
                           |
                           v
                  +-------------------+
                  | Rate Limiter      |
                  | Check Tokens      |
                  +-------------------+
                      /       \
              Tokens Available  Tokens Exhausted
                   /                 \
          Allow Request           Reject Request
           /      \                  |
   +---------------------+      +-------------------+
   | Forward to Backend  |      | Send 429 Response |
   +---------------------+      +-------------------+
Configuring Example
proxies:
  - path: /user
    service: userApi
    middleware:
      rateLimiter:
        enabled: true
        limitRefreshPeriod: 2000 
        limitForPeriod: 5
        maxBurstCapacity: 10
Explanation of Each Rate Limit State
ENABLED
- Definition: Indicates whether the Rate Limiter is active for a specific proxy route.
- Behavior:
- When set to true, all incoming requests are subject to rate limiting.
- When set to false, requests bypass the rate-limiting logic.
 
- When set to 
- Purpose: Provides control over whether rate limiting should apply to a particular route.
LIMIT_REFRESH_PERIOD
- Definition: The interval at which the bucket refills with new tokens.
- Behavior:
- Configured in milliseconds.
- At each interval, limitForPeriodtokens are added to the bucket.
- The bucket accumulates tokens up to maxBurstCapacityif unused.
 
- Purpose: Ensures steady traffic flow while preventing abuse.
- Example: limitRefreshPeriod: 2000refills tokens every 2 seconds.
LIMIT_FOR_PERIOD
- Definition: The number of tokens added to the bucket during each refresh period.
- Behavior:
- Represents the maximum number of requests allowed per interval (limitRefreshPeriod).
- Each request consumes one token.
- Requests are denied when tokens are exhausted.
 
- Represents the maximum number of requests allowed per interval (
- Purpose: Defines the rate of allowed requests to maintain system stability.
- Example: limitForPeriod: 5allows 5 requests per 2-second interval.
MAX_BURST_CAPACITY
- Definition: The maximum number of tokens the bucket can hold, including unused tokens from previous periods.
- Behavior:
- Allows the system to handle sudden bursts of traffic.
- Tokens beyond this value are discarded during a refill.
 
- Purpose: Provides flexibility to accommodate temporary traffic spikes.
- Example: maxBurstCapacity: 6allows up to 6 requests in a single burst.
Workflow
- 
Token Check: - Each incoming request consumes a token.
- If tokens are available, the request is allowed.
- If no tokens are available, the request is denied with a 429 Too Many Requestsresponse.
 
- 
Token Refill: - Tokens are replenished at intervals defined by limitRefreshPeriod.
- Up to limitForPeriodtokens are added, without exceedingmaxBurstCapacity.
 
- Tokens are replenished at intervals defined by 
- 
Burst Handling: - If tokens were not fully utilized in previous periods, they accumulate up to maxBurstCapacity.
- This allows temporary spikes in traffic to be handled gracefully.
 
- If tokens were not fully utilized in previous periods, they accumulate up to