Is the order of data between nodes guaranteed?

hello, I’m trying to call the API in batches

For example, I have an array of 10 keys to use as parameters.
json

[
    {
        "key": "1"
    },
    {
        "key": "2"
    },
    ...
    {
        "key": "10"
    }
]

Use the HTTP request node to run the batch in units of 5 as follows:

{
    "nodes": [
      {
        "parameters": {
          "requestMethod": "POST",
          "url": "https://some-api",
          "jsonParameters": true,
          "options": {
            "batchInterval": 1000,
            "batchSize": 5
          },
          "bodyParametersJson": "={\"key\":\"{{$json[\"key\"]}}\"}",
          "headerParametersJson": "",
          "queryParametersJson": ""
        },
        "name": "HTTP Request",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 1,
        "position": [
          980,
          -420
        ],
        "notesInFlow": false
      }
    ],
    "connections": {}
  }

And the expected result of the API is:

{
    "success": boolean,
    "data": {
        "reqId": string
    }
}

What I want to do here is to combine the parameter (key) passed in when calling the API and the data of the result value and save it as tsv.
I made the following using the executeCommand node.

{
    "nodes": [
      {
        "parameters": {
          "executeOnce": false,
          "command": "=echo \"{{$node[\"Function\"].json[\"key\"]}}\\t{{$node[\"HTTP Request\"].json[\"success\"]}}\\t{{$node[\"HTTP Request\"].json[\"data\"][\"reqId\"]}}\" >> /Users/me/result.tsv"
        },
        "name": "Save File",
        "type": "n8n-nodes-base.executeCommand",
        "typeVersion": 1,
        "position": [
          1380,
          -380
        ]
      }
    ],
    "connections": {}
  }

result file is saved as:

1	true	17a2ca2e-8bbc-49a8-8b9b-bdb7b20bd662
2	true	bd0ea76e-4769-4f1a-9845-aa73152ab458
3	true	20686b48-07c0-41a0-841e-a00563bc6aed
4	true	43854606-86eb-4c38-aa41-ae8e48cec001
5	true	51473bc5-17fa-4f4b-9be4-61bf59807280
6	true	c09901a4-337b-4655-918d-2909a802329f
7	true	ef4c5fb0-a99f-4b9d-9663-29a74cda6f41
8	true	1ddd4d88-f603-4279-97bd-0c5c824141f5
9	true	caca7c5c-d02a-469e-9ceb-e648a1c76fc1
10	true	0baf9a28-abda-4451-87ab-34336fe0ea93

When only 10 calls are tested, it seems that the order of key and reqId is guaranteed.
The question here is whether we can guarantee the data order of each node, even with tens of thousands of requests, as in the results of the 10 tests above.

If the order is not guaranteed, what is a good way to combine the response data of the HTTP request with the data of the previous node?

Thank you in advance.
lee

Hi @YongMoon_Lee, welcome to the community :tada:

n8n would not change the order of items as they are processed sequentially. So the first item before the HTTP request would correspond to the first item after the HTTP request (same for the second, third, etc. item).

Here’s a quick test workflow, you can set any number in the initial Function node if you’d like to double-check this yourself. It uses the /anything endpoint from httpbin.org, which is a great service for testing such scenarios (as it responds simply with the data it has received).

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "responseNumber",
              "value": "={{$json[\"json\"][\"number\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const myNumbers = [...Array(100).keys()];\n\nreturn myNumbers.map(e => { return {\n    json: {\n      myNumber: e\n    }\n  }\n});\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://httpbin.org/anything",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "number",
              "value": "={{$json[\"myNumber\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "responseNumber",
              "value": "={{$json[\"json\"][\"number\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

@MutedJam Thank you :slight_smile:

it really helped a lot

1 Like

Awesome, glad to hear that. Thanks a lot for confirming!