Node-red message delivery sequence

I found this to be an interesting tidbit. It says that the order of message delivery to multiple nodes wired to the same output of another node follows the order in which the wires were connected.

I don’t think anyone should count on this behavior to always be the case since it’s an undocumented “feature” and could change at any time. Maybe put it on the “fun trivia” list.


Although I am sure you understand why this works this way and what it means in terms of automations, others may not so hopefully this brief ramble will help someone :slight_smile:

It works this way because of how node.js is implemented/coded, and it won’t change unless/until node.js becomes fully asynchronous/multi-threaded. When that happens you can expect the results to only vary based on the time the nodes the inject is calling take to complete their task and send their info out.

The reason it works the way it does now is because of how the flow data is stored (json ordering) and therefore triggered. If you want to see it for yourself create a simple flow with an inject node that outputs to multiple debugs.

Export your flow into json code. Now reconnect the nodes in a different order and export the code again.

If you compare the two exampled you will notice that the order you made the connections is the order they are listed inside the flows json. When the flow executes, since it is “single threaded” it sends the commands out in this order step by step as it runs down the list. The “delay” between each node getting its message is in the sub millisecond range, for all or our intents and purposes instant.

For home automation, in general, this “feature” isn’t really of any use, aside from organizing the order in which your data comes back in a way that makes more sense for you/is easier to read in console/logs.

Real world applications needing that level of precision you would want the processing done on the device itself, with relevant data just relayed through NR to other devices that use it.

So in summation, a somewhat useful trick for organizing data and logs, but not something you ever want to be relying on when that small of a timescale matters :slight_smile:

(I tried to avoid being all technical, and made this as generally easy to understand as I could.)