Skip to main content
Version: Next

Quotas Overview

Traditioally, API providers enfore quotas and rate limits to ensure the best distribution and use of their resouces among all their customers, meaning that it is usually enforced by an API Gateway used by providers. At Lunar.dev, we have implemented the consumer side version of every limitation providers are using so users are able to get the most value they can within the limits set by providers.

Lunar Quotas offer a flexible and centralized method for managing and configuring API quotas for the APIs you consume. These quotas are defined by the API provider and can be dividided into sub-quotas by Lunar's internal limits, allowing users to set precise limits on API consumption. Quota management is defined in a yaml files under quotas folder, shared across all flows for each API Provider within a Lunar Gateway, providing a scalable way to allocate and monitor API usage.

The Quota System is a key feature in this platform, enabling users to define quotas based on specific provider limits and internal limits based on your API consumption profile, such as monthly, daily, or other intervals. Quotas are dynamically updated as consumption occurs, ensuring real-time management across flows.

note

Quotas are a passive counter based on the most common limitation strategies used by providers. They can be used in conjuction with a flow to control your APIs, however if they are used on their own they will only generate metrics.


Quota File Structure​

The quota section defines the main constraints on API usage by specifying rate limiting strategies. This primary quota acts as the overarching rule for API requests, applying to all requests that match specified filters (e.g., URLs, headers). Quota's Filter allow quotas to be applied conditionally based on endpoint patterns or request headers, making it adaptable to different usage scenarios and customer types.

The internal_limits section is designed to set more specific constraints within the main quota by defining nested intenal limits that inherit from the main parent quota. Each internal limit can have its own filters and strategies, enabling precise control over distinct user groups or endpoints.

Benefits of Lunar Quota Management​

  • Real-time API Usage Monitoring: Automatically updated as quotas are consumed, ensuring accurate real-time usage statistics across all your consumers.
  • Granular Control: Ability to set quotas based on URLs, headers, and user groups. Nested quotas allow for more detailed control over specific API resources.
  • Scalability: Easily manage and track quotas across multiple API flows and user environments.

Quota Example​

Here’s an example of a quota configuration defined in a quota.yaml file. In this example we see that api.website.com/* has a quota, MyQuota of 1000 requests per hour as set by the provider. We have chosen to futher limit this qupta by implementing the LimitPerMinute internal limit which will allow only 50 requests per minute.

/etc/lunar-proxy/quotas/{fileName}.yaml
quotas:
- id: MyQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
max: 1000
interval: 1
interval_unit: hour

internal_limits:
- id: LimitPerMinute
parent_id: MyQuota
strategy:
fixed_window:
max: 50
interval: 1
interval_unit: minute