Skip to content

Commit

Permalink
Merge pull request #795 from RizaFarheen/riz-update
Browse files Browse the repository at this point in the history
Update rate-limit-workflow.md
  • Loading branch information
RizaFarheen authored Nov 22, 2024
2 parents bbda6d1 + 8556361 commit 25bb753
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions docs/reference-docs/api/workflow/rate-limit-workflow.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Rate Limit Workflow

The **workflow rate limit** limits the number of workflow executions at any given time.
Workflow triggered after exceeding the rate limit will get queued based on the trigger time.
RateLimit config is a part of the workflow definition. The key can be parameterized.
The workflow rate limit controls the number of workflow executions allowed concurrently. Workflows triggered beyond this limit are queued based on their trigger time.

## Input Parameters

| Parameter | Description |
| --------- | ----------- |
| rateLimitConfig | The rate limit settings for workflows. This is part of the workflow definition. |
| rateLimitKey | A unique identifier used to group workflow executions for rate limiting. Accepts [variables from workflow input](https://orkes.io/content/developer-guides/passing-inputs-to-task-in-conductor#sample-expressions), e.g., `${workflow.input.correlationId}`. |
| concurrentExecLimit | The number of workflow executions that can run concurrently for a given key. |

**Sample JSON configuration**

```json
// Workflow definition

"rateLimitConfig": {
"rateLimitKey": "someKey",
"concurrentExecLimit": X
}
```
For example, if `concurrentExecLimit` is set to 3, a maximum of three workflows can be executed at any given time.

## Client SDK Method

<Tabs>
<TabItem value="Java" label="Java">

## Java Example
```shell
RateLimitConfig rateLimitConfig = new RateLimitConfig();
rateLimitConfig.setRateLimitKey("http");
rateLimitConfig.setConcurrentExecLimit(3);
workflowDef.setRateLimitConfig(rateLimitConfig);
```
</TabItem>
</Tabs>

## Examples

Here the execution limit is set as 3, which means that no more than 3 workflows will be allowed to execute at any given time.
<details><summary>Using dynamic rate limits</summary>

For use cases requiring dynamic rate limits, consider the following example:

## Dynamic rate limit.
For a use cases where the rate limit is to be configured dynamically, we can use below example,
```shell
RateLimitConfig rateLimitConfig = new RateLimitConfig();
rateLimitConfig.setRateLimitKey("${workflow.correlationId}");
rateLimitConfig.setConcurrentExecLimit(3);
workflowDef.setRateLimitConfig(rateLimitConfig);
```
So for each correlationId separate rate limiting will be applied.
For example, the workflow is triggered with correlationids 1 and 2, there will be two rate limiting queues for the workflow.
We can create a dynamic rate limit based on input, workflowType, correlationid and version.

In this case, a separate rate limit is applied for each correlation ID. For example, workflows triggered with correlation IDs 1 and 2 will each have their own rate-limiting queues. This approach allows dynamic rate limits based on inputs such as `workflowType`,` correlationId`, or `version`.

</details>

0 comments on commit 25bb753

Please sign in to comment.