# internal architecture of Node-RED

**URL:** <https://discourse.nodered.org/t/internal-architecture-of-node-red/76733>\
**Category:** Core Development\
**Created:** [20 March 2023 08:02 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733 "2023-03-20T08:02:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![YRoshcha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yroshcha/32/77615_2.png) [@YRoshcha](https://discourse.nodered.org/u/YRoshcha)\
**Post date:** [20 March 2023 08:02 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/1 "2023-03-20T08:02:58Z")

</div>

Hello  
Where can I get acquainted with the internal architecture of Node-RED?  
I'm interested in exactly how the nodred works under the hood, how flows work, maybe there is a scheme of work already described.

The issue of horizontal scaling is also interesting.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 March 2023 14:32 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/2 "2023-03-20T14:32:26Z")

</div>

Hi @YRoshcha

This isn't something that is particularly well documented.

There is a high-level description of the modules in the runtime here: [Node-RED](https://nodered.org/docs/api/modules/v/1.3/) - whilst it says that's 1.3, the fundamental structure hasn't changed since then.

Are there particular questions you have? I'd be happy to try to answer them. It may also help us identify what sort of internal architecture documentation would be genuinely useful to produce.

---

<div class="post-metadata">

**Author:** ![YRoshcha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yroshcha/32/77615_2.png) [@YRoshcha](https://discourse.nodered.org/u/YRoshcha)\
**Post date:** [20 March 2023 15:34 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/3 "2023-03-20T15:34:55Z")

</div>

Interested in how node-edit works in principle  
What is flow in terms of node js  
How deploy flow is implemented and what kind of entity as such, if you look at it from the point of view of node js  
How do flows interact with each other inside  
how can projects be scaled horizontally in coded if there are limited hardware resources

---

<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:** [20 March 2023 16:01 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/4 "2023-03-20T16:01:32Z")

</div>

> [@YRoshcha](#):
>
> Interested in how node-edit works in principle

The front end builds a JSON array from the user configured nodes and posts them to the API (runtime / backend)

> [@YRoshcha](#):
>
> What is flow in terms of node js

Flow is a little bit overloaded but in most basic terms, a flow is 2 or more connected nodes.  
When a flow is deployed, the runtime instantiates objects based on the nodes in the JSON (flows).

> [@YRoshcha](#):
>
> How deploy flow is implemented and what kind of entity as such

deploy (the front end operation) sends a JSON representation of what you have in the the graphical canvas (the node-red editor).

> [@YRoshcha](#):
>
> How do flows interact with each other inside

In the runtime, messages are delivered to the nodes based on the `wires` property in the instantiated nodes. There is more to this but this basic info should give you a flavour of what is happening.

> [@YRoshcha](#):
>
> how can projects be scaled horizontally in coded if there are limited hardware resources

You can easily run multiple Node-RED projects and use one of many established mechanisms to coordinate messages between them. For example, you can use [shared-subscriptions](https://www.hivemq.com/blog/mqtt5-essentials-part7-shared-subscriptions/) to load balance or a database shared among your instances, or create your own message queue, or ...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 March 2023 17:56 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/5 "2023-03-20T17:56:06Z")

</div>

> [@YRoshcha](#):
>
> What is flow in terms of node js

To be clear, while the descriptions of Node-RED all talk about "passing messages between nodes" - this is perhaps slightly confusing for those people looking at the internals since the reality is that a msg object is mostly passed by reference between node instances. Though there are some notable exceptions where a msg object is cloned to try and avoid async change issues.

The runtime of each Node (capital N) is a Node.js module and is registered to Node-RED. The exported function is run when Node-RED starts. It in turn registers another function that is run for each node instance (small n) added to a flow. That 2nd function registers a 3rd function if it accepts input messages and it is that inner function that runs whenever a msg is received by the node instance (via event handling).

---

<div class="post-metadata">

**Author:** ![YRoshcha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yroshcha/32/77615_2.png) [@YRoshcha](https://discourse.nodered.org/u/YRoshcha)\
**Post date:** [21 March 2023 11:14 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/7 "2023-03-21T11:14:00Z")

</div>

thanks, this is known, interested in a deeper structure

---

<div class="post-metadata">

**Author:** ![YRoshcha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yroshcha/32/77615_2.png) [@YRoshcha](https://discourse.nodered.org/u/YRoshcha)\
**Post date:** [21 March 2023 11:15 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/8 "2023-03-21T11:15:27Z")

</div>

> [@TotallyInformation](#):
>
> To be clear, while the descriptions of Node-RED all talk about "passing messages between nodes" - this is perhaps slightly confusing for those people looking at the internals since the reality is that a msg object is mostly passed by reference between node instances. Though there are some notable exceptions where a msg object is cloned to try and avoid async change issues.
> 
> The runtime of each Node (capital N) is a Node.js module and is registered to Node-RED. The exported function is run when Node-RED starts. It in turn registers another function that is run for each node instance (small n) added to a flow. That 2nd function registers a 3rd function if it accepts input messages and it is that inner function that runs whenever a msg is received by the node instance (via event handling).

that is, each node is a function that is executed sequentially?

---

<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:** [21 March 2023 11:57 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/9 "2023-03-21T11:57:24Z")

</div>

> [@YRoshcha](#):
>
> interested in a deeper structure

To what end? What do you hope to achieve by understanding the finer details? I don't know how gravity works but I understand what will happen if I jump off the roof!

I have answered your questions from a users perspective - you shouldn't really need any more info than this to get started.

> [@YRoshcha](#):
>
> interested in a deeper structure

If you wish to completely understand the internals, then you could always look through the publicly available source code.

Alternatively, if you have specific questions we can certainly answer those.

---

<div class="post-metadata">

**Author:** ![YRoshcha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yroshcha/32/77615_2.png) [@YRoshcha](https://discourse.nodered.org/u/YRoshcha)\
**Post date:** [21 March 2023 12:21 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/10 "2023-03-21T12:21:41Z")

</div>

> [@Steve-Mcl](#):
>
> To what end? What do you hope to achieve by understanding the finer details? I don't know how gravity works but I understand what will happen if I jump off the roof!
> 
> I have answered your questions from a users perspective - you shouldn't really need any more info than this to get started.

in order to start this information is really enough, but this information is not enough to stabilize my system

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 March 2023 12:26 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/11 "2023-03-21T12:26:42Z")

</div>

> [@YRoshcha](#):
>
> each node is a function that is executed sequentially?

Sequential is a bit of a slippery concept in JavaScript and Node.js 🙂

Since node processing can be partially or fully asynchronous. But in essence, yes, that's how I understand it.

Obviously though, one node can have multiple output wires going to different nodes. so the actual execution order might be hard to understand. I believe that the order of adding to the flow has an impact.

---

<div class="post-metadata">

**Author:** ![YRoshcha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yroshcha/32/77615_2.png) [@YRoshcha](https://discourse.nodered.org/u/YRoshcha)\
**Post date:** [21 March 2023 12:30 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/12 "2023-03-21T12:30:56Z")

</div>

> [@TotallyInformation](#):
>
> Sequential is a bit of a slippery concept in JavaScript and Node.js 🙂
> 
> Since node processing can be partially or fully asynchronous. But in essence, yes, that's how I understand it.
> 
> Obviously though, one node can have multiple output wires going to different nodes. so the actual execution order might be hard to understand. I believe that the order of adding to the flow has an impact.

I'm just trying to understand what is a flow: a flow or a node

if a node, then it turns out that a flow is generated for each node  
if it is a flow, then for each flow there is a flow and functions in it that branch to other functions depending on the output of the node

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 March 2023 20:39 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/13 "2023-03-21T20:39:30Z")

</div>

> [@YRoshcha](#):
>
> a flow: a flow or a node

Urm, a flow is a flow 😁 It is defined by a series of node instances that are related via wires - those are simply a concept that helps understand the sequencing of calls to the message handler in each node instance. Well, that's how I understand them anyway. I expect that Nick and other core devs could explain it better than I.

> [@YRoshcha](#):
>
> for each flow there is a flow and functions in it that branch to other functions depending on the output of the node

I guess I'd put it as the flow is defined by node instances related to each other via the wires (the flows file makes this clear as it is remarkably simple in structure). But the actual processing is about the sequence of calls as you say since node-red is not, fundamentally, a message queue service but rather, a complex node.js app made up of many interconnected modules bound together by the core runtime.

---

<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:** [20 May 2023 20:39 UTC](https://discourse.nodered.org/t/internal-architecture-of-node-red/76733/14 "2023-05-20T20:39:40Z")

</div>

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