# Running a flow triggered via HTTP concurrently

**URL:** <https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076>\
**Category:** General\
**Tags:** http-request\
**Created:** [30 September 2024 13:00 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076 "2024-09-30T13:00:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![venomancer](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@venomancer](https://discourse.nodered.org/u/venomancer)\
**Post date:** [30 September 2024 13:00 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/1 "2024-09-30T13:00:49Z")

</div>

I am sorry if that has been answered somewhere else already, I haven't found exactly what I need via search.

Let's say I'm building a flow that starts with an http-in node so that the flow can be triggered via an HTTP endpoint.

Inside of the flow, there is some data processing such as reading from/writing to a database, sending notifications, etc.

Currently, with just http-in -\> json -\> delay (for testing purposes) -\> http-out, if I trigger the flow in multiple browser tables, they all run sequentially so that the second invocation waits until the first one finishes.

I understand that most likely this is due to how Node.js works, but is there any way to have parallel instances of the same flow?

To explain better the usecase: a flow for me is a template for a pipeline which can be run by multiple users at the same time, and it would be unfortunate to run all instances one at a time.

Thanks!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 September 2024 13:40 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/2 "2024-09-30T13:40:21Z")

</div>

> [@venomancer](#):
>
> the second invocation waits until the first one finishes

Do you mean it is waiting for the http out to complete before accepting the next http in? That should not happen.

---

<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:** [30 September 2024 13:49 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/3 "2024-09-30T13:49:28Z")

</div>

> [@venomancer](#):
>
> Currently, with just http-in -\> json -\> delay (for testing purposes) -\> http-out, if I trigger the flow in multiple browser tables, they all run sequentially so that the second invocation waits until the first one finishes.

This is not true.

#### GIF demonstrating async (non sequential) operation

![WindowsTerminal_QSZVo8nuxo](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5384f717151103e19d39e7ba520c9651d1df4b28.gif)

#### demo flow

```auto
[{"id":"10db3e6940831566","type":"http in","z":"65608a30f8a8cec4","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":470,"y":600,"wires":[["fe98d449ecd63dc1","5150a9b9cf5c5f16"]]},{"id":"fe98d449ecd63dc1","type":"function","z":"65608a30f8a8cec4","name":"function 4","func":"msg.payload = \"You specified a delay of \" + msg.req.query.delay + \"ms\"\n\nmsg.delay = msg.req.query.delay\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":600,"wires":[["b680ee84852ef304"]]},{"id":"cab6ead2adc71b78","type":"http response","z":"65608a30f8a8cec4","name":"","statusCode":"","headers":{},"x":930,"y":600,"wires":[]},{"id":"b680ee84852ef304","type":"delay","z":"65608a30f8a8cec4","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":770,"y":600,"wires":[["cab6ead2adc71b78"]]},{"id":"5150a9b9cf5c5f16","type":"debug","z":"65608a30f8a8cec4","name":"debug 197","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":680,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![venomancer](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@venomancer](https://discourse.nodered.org/u/venomancer)\
**Post date:** [30 September 2024 13:55 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/4 "2024-09-30T13:55:30Z")

</div>

```auto
[
    {
        "id": "106100fc7cbdc224",
        "type": "http in",
        "z": "ae2f93afd21df814",
        "name": "test-flow",
        "url": "test-flow",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 100,
        "y": 360,
        "wires": [
            [
                "7f2b789a8ae3ed50"
            ]
        ]
    },
    {
        "id": "56cfb5bbb2f7b604",
        "type": "http response",
        "z": "ae2f93afd21df814",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 790,
        "y": 340,
        "wires": []
    },
    {
        "id": "7f2b789a8ae3ed50",
        "type": "json",
        "z": "ae2f93afd21df814",
        "name": "",
        "property": "req.query",
        "action": "",
        "pretty": false,
        "x": 350,
        "y": 360,
        "wires": [
            [
                "9e7cd1649a3338e3"
            ]
        ]
    },
    {
        "id": "9e7cd1649a3338e3",
        "type": "delay",
        "z": "ae2f93afd21df814",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 560,
        "y": 360,
        "wires": [
            [
                "56cfb5bbb2f7b604"
            ]
        ]
    }
]

```

Here is mine. Maybe, I just created the flow in a stupid way, but my second tab does wait for the first one to complete with this setup.

---

<div class="post-metadata">

**Author:** ![venomancer](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@venomancer](https://discourse.nodered.org/u/venomancer)\
**Post date:** [30 September 2024 14:05 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/5 "2024-09-30T14:05:26Z")

</div>

Let me clarify (see the flow JSON above).

What happens is that if I have two tabs where I trigger /test-flow at the same time, the second one finishes in 10 seconds, not in 5-6 as if waiting for the first one to finish first.

The example suggested by @Steve-Mcl, however, works but I don't understand why mine doesn't now 🙂

---

<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:** [30 September 2024 14:08 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/6 "2024-09-30T14:08:20Z")

</div>

Try setting your delay node to a random time, then you may see that the second http request can finish before the first.

---

<div class="post-metadata">

**Author:** ![venomancer](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@venomancer](https://discourse.nodered.org/u/venomancer)\
**Post date:** [30 September 2024 14:10 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/7 "2024-09-30T14:10:58Z")

</div>

Yeah, that makes sense, but I still don't understand what happens in my simple example above.

If I deploy the flow and then trigger it in 3 tabs in a row, the last one will get a response in ~15 seconds. I do not expect exactly 5 seconds, this is all concurrent, I understand, but they seem to be running sequentially which makes me think (baed on the example above that works differently) that something is clearly wrong in my flow.

---

<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:** [30 September 2024 14:22 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/8 "2024-09-30T14:22:42Z")

</div>

That maybe the browser executing each tab concurrently as they are calling same page. Try in different browsers and/or different devices.

---

<div class="post-metadata">

**Author:** ![venomancer](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@venomancer](https://discourse.nodered.org/u/venomancer)\
**Post date:** [30 September 2024 14:25 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/9 "2024-09-30T14:25:14Z")

</div>

Okay, this even sounds strange, but it's subjectively worse when the delay is fixed.  
In your example, if I run 2 CURLs or browser tabs with delay=5000, one of them finishes in ~5s, but the second one takes about 10s. Is that expected?

---

<div class="post-metadata">

**Author:** ![venomancer](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@venomancer](https://discourse.nodered.org/u/venomancer)\
**Post date:** [30 September 2024 14:27 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/10 "2024-09-30T14:27:30Z")

</div>

It seems that you're right. Running 1 with curl and 1 in the browser works as expected. Weird. Looks like some browser special behavior. Thanks everyone for your help!

---

<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:** [14 October 2024 14:28 UTC](https://discourse.nodered.org/t/running-a-flow-triggered-via-http-concurrently/92076/11 "2024-10-14T14:28:16Z")

</div>

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