Client Side Limiting Flow
The Client-Side Limiting Flow regulates API traffic by enforcing predefined Quotas within the flow. This ensures that API usage stays within limits, preventing overconsumption and maintaining stable integration. The flow dynamically manages requests and provides appropriate responses when quotas are exceeded using the Limiter and GenerateResponse processors.
Scenarios
- Quota Enforcement: The flow applies traffic limits based on configured quotas, ensuring that API requests adhere to predefined thresholds for visibility and management.
- Custom Responses: Configure specific messages or status codes when limits are reached, giving users clear feedback on quota breaches.
- Quota Segmentation: The flow enforces quotas based on attributes like headers or URLs, allowing for granular traffic control, such as setting different limits for production and staging environments.
- Noisy Neighbor Prevention: Ensure that high-traffic clients do not negatively impact others by enforcing client-specific quotas within the flow.
- Proactive Client-Side Throttling: Protect API provider resources by enforcing traffic limits directly on the client side, ensuring responsible and efficient API consumption.
Flow Components
Flow Example
- API requests to
httpbin.com/*
are throttled with a maximum of 100 requests per minute. - If the quota is exceeded, the flow returns a 429 HTTP status code along with the message: "Quota Exceeded. Please try again later."
/etc/lunar-proxy/flows/flow.yaml
name: ClientSideLimitingFlow
filter:
url: httpbin.com/*
processors:
RateLimiter:
processor: Limiter
parameters:
- key: quota_id
value: MyQuota
GenerateResponseLimitExceeded:
processor: GenerateResponse
parameters:
- key: status
value: 429
- key: body
value: "Quota Exceeded. Please try again later."
- key: Content-Type
value: text/plain
flow:
request:
- from:
stream:
name: globalStream
at: start
to:
processor:
name: RateLimiter
- from:
processor:
name: RateLimiter
condition: above_limit
to:
processor:
name: GenerateResponseLimitExceeded
- from:
processor:
name: RateLimiter
condition: below_limit
to:
stream:
name: globalStream
at: end
response:
- from:
processor:
name: GenerateResponseLimitExceeded
to:
stream:
name: globalStream
at: end
/etc/lunar-proxy/quota/quota.yaml
quotas:
- id: MyQuota
filter:
url: httpbin.com/*
strategy:
fixed_window:
static:
max: 100
interval: 1
interval_unit: minute