# Allow random range delay

**URL:** <https://discourse.nodered.org/t/allow-random-range-delay/95230>\
**Category:** Feature Requests\
**Tags:** delay, rate-limit\
**Created:** [8 February 2025 00:06 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230 "2025-02-08T00:06:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eden881](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eden881](https://discourse.nodered.org/u/eden881)\
**Post date:** [8 February 2025 00:06 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/1 "2025-02-08T00:06:46Z")

</div>

I'd love the option to delay & rate-limit messages using a range to select a random amount of time.  
For example: delay messages to 3-6/sec, so that each message in the queue will wait between 3 to 6 seconds.

It helps tremendously when dealing with a rate-limited API several times down the line, because it alleviates the need to micro-manage the delays.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 February 2025 01:00 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/2 "2025-02-08T01:00:55Z")

</div>

Welcome to the forum @eden881

You can use a Random node (node-red-node-random, you may need to install it in Manage Palette) to insert a msg.delay between 3000 and 5000 (milliseconds) into every message.  
The delay node has an option to override the delay with msg.delay.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/2440383eeed90300bd1c392c5a757d0a682b09d8.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/optimized/3X/e/c/ec9025f501b0057e07f7c2a7735f1ae7188ba690_2_517x42.png)

In rate-limit mode there is an option to accept msg.rate. I don't know what effect this has!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e620b2e0cce1856877c1c4a499f35889627df1ed.png)

---

<div class="post-metadata">

**Author:** ![eden881](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eden881](https://discourse.nodered.org/u/eden881)\
**Post date:** [8 February 2025 04:59 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/3 "2025-02-08T04:59:32Z")

</div>

Oh, that’s clever!  
I didn’t know about the random node. If it works in rate-limit mode it solves my issue completely.  
I’ll give it a try, thanks.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [8 February 2025 07:13 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/4 "2025-02-08T07:13:55Z")

</div>

Why does a random delay help ? If you know the ratelimit further down the flow why not just apply it using the rate limit mode of the delay node ? It is only setting the maximum rate allowed.

---

<div class="post-metadata">

**Author:** ![eden881](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eden881](https://discourse.nodered.org/u/eden881)\
**Post date:** [8 February 2025 13:40 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/5 "2025-02-08T13:40:24Z")

</div>

Let’s say the API allows up to 1 msg per second, and I hit it at two points in my flow.  
If I set both delay nodes to rate limit at 1/sec, I’ll have a situation where both delay nodes will essentially fire at almost the same time, because each message is delayed at the first stop and then clears the second stop condition.  
In my case I also split messages between the API calls which worsens this issue significantly. Using randomness helps to minimize the chance of this issue.

More info can be found here (this article is about back off strategies, but the jitter part applies here too):

> **[Exponential Backoff And Jitter | Amazon Web Services](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)**
>
> Update (May 2023): After 8 years, this solution continues to serve as a pillar for how Amazon builds remote client libraries for resilient systems. Most AWS SDKs now support exponential backoff and jitter as part of their retry behavior when using...

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [8 February 2025 13:50 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/6 "2025-02-08T13:50:22Z")

</div>

If you are using multiple API calls (ie different flows) but have an overall rate limit then you could divide the rate limit across each delay node (in rate limit node) ie assign half to each (if two flows) etc.

Or you could use a single rate limit node and feed all flows through it - using the msg.topic to identify each (see below)... eg set msg.topic to the url for the api so they are unique - but then after the delay node - move the topic to msg.url before calling the http request node... or something like that.  
eg

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eba8b323291a76cfd4f0c14469ec5e1120c14ac2.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 February 2025 13:51 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/7 "2025-02-08T13:51:31Z")

</div>

You could make a reusable flow via a link-in / link-call (like a single subroutine that only has a single delay node http-request)

This makes it easier to maintain too

`[flow 1 do something]----[link-call: "API"]----[do stuff with response]`  
`[flow 2 do something]----[link-call: "API"]----[do stuff with response]`  
`[flow 3 do something]----[link-call: "API"]----[do stuff with response]`

`[link-in "API"]----[rate limit]----[http-request]----[link-out (return)]`

---

<div class="post-metadata">

**Author:** ![eden881](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eden881](https://discourse.nodered.org/u/eden881)\
**Post date:** [8 February 2025 15:08 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/8 "2025-02-08T15:08:05Z")

</div>

> [@Steve-Mcl](#):
>
> You could make a reusable flow via a link-in / link-call

After some experimentation this seems to be the best solution to my issue.  
I didn't know about link out's return mode, thanks!

I actually only used the rate limit node in the 2nd flow since my web requests hits different API routes. It works great.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [9 April 2025 15:08 UTC](https://discourse.nodered.org/t/allow-random-range-delay/95230/9 "2025-04-09T15:08:35Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
