# Out of order http responses

**URL:** <https://discourse.nodered.org/t/out-of-order-http-responses/66809>\
**Category:** General\
**Tags:** http-request\
**Created:** [23 August 2022 11:43 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809 "2022-08-23T11:43:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [23 August 2022 11:43 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/1 "2022-08-23T11:43:56Z")

</div>

Hello

I have a problem of possible out-of-order processing in my flow  
The flow goes through an http-request, which I imagine is processed asynchronously. This introduce an uncertainty on the execution order.  
On this example, we can see that the order of the messages at the output are not the same as the input. They can eventually be different at each execution.

```auto
[{"id":"9a86d59e88442f2c","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"9342a516f1bafda0","type":"inject","z":"9a86d59e88442f2c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"title\":\"ITEM A\"},{\"title\":\"ITEM B\"},{\"title\":\"ITEM C\"},{\"title\":\"ITEM D\"},{\"title\":\"ITEM E\"},{\"title\":\"ITEM F\"},{\"title\":\"ITEM G\"},{\"title\":\"ITEM H\"}]","payloadType":"json","x":430,"y":220,"wires":[["377fb634af59c3fa"]]},{"id":"fc962674bf19f1e9","type":"debug","z":"9a86d59e88442f2c","name":"Debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"Debug 1: title:\" & msg.save_details.title","targetType":"jsonata","statusVal":"","statusType":"auto","x":1020,"y":160,"wires":[]},{"id":"377fb634af59c3fa","type":"split","z":"9a86d59e88442f2c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":550,"y":220,"wires":[["b7a7fc71bc9eb7cc"]]},{"id":"9e139c96772f9582","type":"http request","z":"9a86d59e88442f2c","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://google.com","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1050,"y":220,"wires":[["c651b52621a1c3d4"]]},{"id":"b7a7fc71bc9eb7cc","type":"change","z":"9a86d59e88442f2c","name":"save details","rules":[{"t":"set","p":"save_details","pt":"msg","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":220,"wires":[["fc962674bf19f1e9","9e139c96772f9582"]]},{"id":"c651b52621a1c3d4","type":"debug","z":"9a86d59e88442f2c","name":"Debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"Debug 2: title:\" & msg.save_details.title","targetType":"jsonata","statusVal":"","statusType":"auto","x":1220,"y":220,"wires":[]}] 

```

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

Unfortuntately in that flow, I need to be sure that the http-request are executed at the server side in the right order.

So far the only workaround I found is to add a rate limiter before the http-request not to insure the flow is completed before the next request is performed.

```auto
[{"id":"9a86d59e88442f2c","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"9342a516f1bafda0","type":"inject","z":"9a86d59e88442f2c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"title\":\"ITEM A\"},{\"title\":\"ITEM B\"},{\"title\":\"ITEM C\"},{\"title\":\"ITEM D\"},{\"title\":\"ITEM E\"},{\"title\":\"ITEM F\"},{\"title\":\"ITEM G\"},{\"title\":\"ITEM H\"}]","payloadType":"json","x":430,"y":220,"wires":[["377fb634af59c3fa"]]},{"id":"fc962674bf19f1e9","type":"debug","z":"9a86d59e88442f2c","name":"Debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"Debug 1: title:\" & msg.save_details.title","targetType":"jsonata","statusVal":"","statusType":"auto","x":1020,"y":160,"wires":[]},{"id":"377fb634af59c3fa","type":"split","z":"9a86d59e88442f2c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":550,"y":220,"wires":[["7b21bb9c815f61ef"]]},{"id":"9e139c96772f9582","type":"http request","z":"9a86d59e88442f2c","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://google.com","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1050,"y":220,"wires":[["c651b52621a1c3d4"]]},{"id":"b7a7fc71bc9eb7cc","type":"change","z":"9a86d59e88442f2c","name":"save details","rules":[{"t":"set","p":"save_details","pt":"msg","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":220,"wires":[["fc962674bf19f1e9","9e139c96772f9582"]]},{"id":"c651b52621a1c3d4","type":"debug","z":"9a86d59e88442f2c","name":"Debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"Debug 2: title:\" & msg.save_details.title","targetType":"jsonata","statusVal":"","statusType":"auto","x":1220,"y":220,"wires":[]},{"id":"7b21bb9c815f61ef","type":"delay","z":"9a86d59e88442f2c","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":700,"y":220,"wires":[["b7a7fc71bc9eb7cc"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/050175cf1392f756784e6903ab3ae2f73f2eef9d.png)

This has problems as if I want it to be relliable, I need a sufficient delay which is drastically slowing down my flow.  
Is there any better solution to insure that the http-request is performed in an "atomic" way ?

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:** [23 August 2022 12:19 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/2 "2022-08-23T12:19:13Z")

</div>

Yes - you can use the delay node in rate limit mode - set the rate to max you will allow, and let them queue up.... when you get a successful response create a feedback with ONLY a `msg.flush` set to `1` to release the next message.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 August 2022 12:26 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/3 "2022-08-23T12:26:37Z")

</div>

Do they need to be executed in the correct order, or do you just need them returned in correct order?

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [23 August 2022 15:32 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/4 "2022-08-23T15:32:48Z")

</div>

@dceejay  
Thanks, working like a charm  
I did as below with a function node with only `return {'flush': 1};` and it works fine  
I first tried with a change node to set `msg.flush` but it started an endless loop probably because the payload and other fields were still there.  
Is there another way than a function node to build a message with only `msg.flush = 1` ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/3875828a6e44bfb36780947eba1dc99d3967f8e8.png)

@E1cid  
I need the request to be executed in the same order on the server.  
As I don't want to assume anything about the quieing on the server, I prefer to get the response before sending the next.  
It may be possible that the server queue and execute in order, and that only the responses are out of order but I need to be 100% sure so the above solution fullfill my need.  
But happy to hear about another one if you have. Always good to learn a trick 😃

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 August 2022 15:40 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/5 "2022-08-23T15:40:55Z")

</div>

I have a solution to have the returns in correct order, but it would only be of use to you if you did not care about what order they are executed. If the order they are executed does not matter, you could then send all request and not have any delay, other than the time it takes for longest request response.

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [23 August 2022 19:20 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/6 "2022-08-23T19:20:41Z")

</div>

Ok  
So not a solution for my today need 😄  
I'll keep it in mind  
Thanks

---

<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:** [22 October 2022 19:21 UTC](https://discourse.nodered.org/t/out-of-order-http-responses/66809/7 "2022-10-22T19:21:10Z")

</div>

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