- Rate: You can specify a maximum number of calls that can be made to your endpoint within a certain time period.
- Parallelism: You can set a limit on the number of concurrent calls to your endpoint.
Choose Flow Control Key
To use flow control, you need to choose a key first. This key is used to count the number of calls made to your endpoint.The limits are applied per flow-control key, not per URL. This means that you can use the same key for different URLs to apply the same limits to them.
There are no limits to number of keys you can use.
Decide Limits
Decide which limits you want to apply. You can choose to apply only rate limit, only parallelism limit, or both.For instance, if you want to limit the number of calls to 10 per minute, you can set the rate to 10 and the period to 1 minute. If you want to limit the number of concurrent calls to 5, you can set the parallelism limit to 5.
Rate and Period Parameters
Therate parameter specifies the maximum number of calls allowed within a given period. The period parameter allows you to specify the time window over which the rate limit is enforced. By default, the period is set to 1 second, but you can adjust it to control how frequently calls are allowed. For example, you can set a rate of 10 calls per minute as follows:
Parallelism Limit
The parallelism limit is the number of calls that can be active at the same time. Active means that the call is made to your endpoint and the response is not received yet. You can set the parallelism limit to 10 calls active at the same time as follows:Rate, Parallelism, and Period Together
All three parameters can be combined. For example, with a rate of 10 per minute, parallelism of 20, and a period of 1 minute, QStash will trigger 10 calls in the first minute and another 10 in the next. Since none of them will have finished, the system will wait until one completes before triggering another.Management API
You can inspect flow control keys programmatically using theflowControl namespace on the client.
Get a single flow control key
Returns the current state and metrics for one flow control key.| Field | Description |
|---|---|
flowControlKey | The flow control key name |
waitListSize | Number of messages currently waiting in the queue |
parallelismMax | Configured maximum concurrent messages (if set) |
parallelismCount | Number of messages currently running in parallel |
rateMax | Configured maximum messages per rate period (if set) |
rateCount | Number of messages dispatched in the current rate period |
ratePeriod | Rate period length in seconds |
ratePeriodStart | Unix timestamp when the current rate period started |
Get global parallelism
Returns the global parallelism usage across all flow control keys.| Field | Description |
|---|---|
parallelismMax | The maximum global parallelism |
parallelismCount | The current number of active requests globally |
Monitor
You can monitor wait list size of your flow control key’s from the consoleFlowControl tab.
