Intro
When we reach out to an API service, there are a number of times that we are able to hit that service. In most cases, we won't hit that service's limit manually. Imagine clicking the login page for your favorite website as many times as you can. You probably aren't going to click it 1,000 times a second. However, when we are using automation, we can easily exceed that barrier. By creating buffer between a service we can stay within their threshold of reason.
Typically, if we go past a rate limit, the service will no longer allow us to make requests or give us a "cool down" period during which the number of requests we can make is throttled.
How do you leverage action options?
Rate limiting is a common hurdle when working with APIs. By leveraging action options like “Retry on Status” and setting appropriate retry counts, we can handle these limits gracefully without interrupting the flow.
Press Play/Pause to follow along with the GIF below
Example steps:
Select an HTTP request
Scroll down on the properties panel and click options
Select Retry on Status
Configure the status you want to perform additional attempts
Status 429 means that the service is busy, so having multiple attempts can be a great way to provide error handling.
From the options, also add in retries
This lets you choose how many times you will retry an HTTP against a service
How do you create dynamic delays?
When dealing with large data sets, sometimes it’s necessary to explode an array to manage the data better. By applying dynamic delays and leveraging basic math functions (+, -, *, etc.), we can control the rate at which data is processed.
Press Play/Pause to follow along with the GIF below
Example steps:
Review the event data from a previously exploded action
Notice how there are events for each item from the explode
Drag in an event transform after the explode
Connect the event transform that is in explode mode
Set the name to "Delay"
Set the mode to "Delay"
Delete the text under seconds
Click + and then value
Enter in a value from the explode like the index
By referencing previous data we can dynamically effect the seconds counter of the delay
Add a * after the value and put in 5
Here we are able to apply some math directly into the formula widget
Taking the index and multiplying by 5
We can also do things like -, +, and /
Run from the initial action and review the logs of the delay
In the logs you'll see when the delay will execute as well as the number of seconds. Notice how the math effected the number to compound
How do you apply throttling?
If you are in a situation that you want to limit the amount of throughput for your story you can implement some rate limiting. To adhere to API rate limits, we implement throttling. Throttling helps to control the pace of our requests, ensuring we stay within the allowed limits while still efficiently processing data.
Press Play/Pause to follow along with the GIF below
Example steps:
Drag in an event transform after the explode
Connect the event transform that is in explode mode
Set the name to "Throttle"
Set the mode to "Throttle"
Run from the initial action and review the logs of the delay
You'll see the event data number slowly tick upwards after some time has passed. The throttle makes it so we slowly let event data flow through this action. It's a great way to ensure you don't have too many requests going through to a service via an HTTP request.
Most services have a limit on how many times you can hit their service. This could be a rate limit per minute / hour / day.