Skip to main content
All CollectionsHow-tosArticles
Example Approach: API Rate Limiting
Example Approach: API Rate Limiting

In this article we'll explore a few approaches around handling rate limiting

Yanni Hajioannou avatar
Written by Yanni Hajioannou
Updated over a week ago

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:

  1. Select an HTTP request

  2. Scroll down on the properties panel and click options

  3. Select Retry on Status

    1. Configure the status you want to perform additional attempts

    2. Status 429 means that the service is busy, so having multiple attempts can be a great way to provide error handling.

  4. From the options, also add in retries

    1. 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:

  1. Review the event data from a previously exploded action

    1. Notice how there are events for each item from the explode

  2. Drag in an event transform after the explode

  3. Connect the event transform that is in explode mode

  4. Set the name to "Delay"

  5. Set the mode to "Delay"

  6. Delete the text under seconds

  7. Click + and then value

  8. Enter in a value from the explode like the index

    1. By referencing previous data we can dynamically effect the seconds counter of the delay

  9. Add a * after the value and put in 5

    1. Here we are able to apply some math directly into the formula widget

    2. Taking the index and multiplying by 5

    3. We can also do things like -, +, and /

  10. Run from the initial action and review the logs of the delay

    1. 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:

  1. Drag in an event transform after the explode

  2. Connect the event transform that is in explode mode

  3. Set the name to "Throttle"

  4. Set the mode to "Throttle"

  5. Run from the initial action and review the logs of the delay

    1. 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.

    2. Most services have a limit on how many times you can hit their service. This could be a rate limit per minute / hour / day.

Did this answer your question?