Comparison
MQTT broker versus direct TCP from a Node-RED edge device
Short answer
Both paths make the edge device open the connection as a client. MQTT is TCP plus a broker — one address at the publisher, TLS on 8883, a unique client ID per client, topic-based delivery — while a direct tcp out to tcp in link is faster to build but pins the publisher to each consumer's address and port. Build direct TCP for one fixed pair; build the broker for anything that grows.
On this page
- Both paths start with an outbound client connection
- The two builds in Node-RED
- Broker link versus direct TCP link
- Ports, TLS and certificate checking on the broker path
- The client ID rule the broker enforces
- Counting sessions and ports: one Temperature publisher, one subscriber
- Where each path fails
- The decision
- Questions asked
Both paths make the same first move: the edge Node-RED device opens a TCP connection outward, so it is the client in either build and nothing has to listen on it. The difference is what answers at the far end. MQTT is TCP with a broker in the middle — one address at the publisher, one listener at the broker, delivery by topic. A direct tcp out to tcp in link drops the broker and pins the sender to the consumer's address and port. Wire the direct link for one fixed pair of endpoints; put a broker in the middle as soon as a second consumer, a moveable address or per-client credentials enter the picture.
Both paths start with an outbound client connection #
In both variants the sending Node-RED dials first and the far end only accepts. The mqtt out node is a client that opens one session to the broker, and the mqtt in node on the receiving host is also a client, opening its own session to the same broker: an MQTT connection always runs between one client and one broker, and clients never connect to each other. On the direct path, tcp out is the client that dials the receiver's address and tcp in is the listener that accepts it.
Neither build needs an inbound firewall rule on the edge device. What you open instead is one port on the broker host, or one listening port on every receiving host.
The two builds in Node-RED #
The broker build: an inject node fires on a repeat interval into the source node — in the usual test flow, a random value named Temperature — and feeds it to a debug node and mqtt out. The mqtt out node points at the broker's address on the TLS port, protocol MQTT V3.1.1, with the client ID and credentials defined for this one client, the Use TLS option enabled, and the topic set to Temperature. On the receiving host, mqtt in points at the same broker with that host's own client ID and credentials, subscribes to the single topic Temperature, and feeds debug. Deploy both flows and each node reports Connected; a blue dot means undeployed changes.
The direct build: the same source flow swaps mqtt out for tcp out. Set the at host field to the receiving host's IP address and pick a port; tcp in on the receiver carries the same port and a rule for where one reading ends, because a TCP session is a byte stream with no message marks. Until the receiver is deployed and listening, tcp out shows Disconnected — that is the expected state, not a fault in the sender's flow.
Broker link versus direct TCP link #
| MQTT through a broker | Direct TCP in Node-RED | |
|---|---|---|
| Who opens the connection | Both endpoints dial out to the broker as clients | The sender's tcp out dials; the receiver's tcp in listens |
| Nodes | mqtt out and mqtt in |
tcp out and tcp in |
| Port | 1883 plaintext, 8883 with TLS | Any free port, set to the same value at both ends |
| What the sender holds | One address: the broker | One address and one port per consumer |
| Adding a consumer | One new subscriber; no change at the sender | One more tcp out and one more listener |
| Message structure | Topic, payload and a QoS flag (0 at most once, 1 at least once, 2 exactly once) | A raw byte stream; you define where one reading ends |
| Credentials | Per client ID and user | None at the protocol level |
| Extra process | A broker to install, secure, restart and back up | None |
MQTT rides on TCP, so the per-link transport is identical in both builds. The broker just inserts one more stop between sender and receiver, and that stop is what buys the decoupling.
Ports, TLS and certificate checking on the broker path #
MQTT's plaintext default port is 1883; with TLS the broker listens on 8883, and you set that port together with the Use TLS option in the client's broker configuration. A plaintext client pointed at the TLS port fails the handshake instead of connecting quietly: the node sits in Connecting and the broker rejects the exchange, which is the pattern behind Node-RED MQTT fails when the broker rejects plain MQTT.
With TLS enabled, the Verify server certificate checkbox decides whether the client checks who answered. Unchecked, the traffic stays encrypted but any server certificate is accepted, which is reasonable only inside a network you control. On any link that leaves the machine network, keep verification on and give the client a chain from a CA you manage — the setup and renewal are covered in Configuring MQTT TLS certificates in Node-RED on an edge PC. If the handshake still stalls after that, trace it from the client's side as in MQTT TLS connects but no CONNACK: find the failing hop.
The client ID rule the broker enforces #
A broker accepts exactly one connection per client ID. Give the publisher and every subscriber their own client ID and their own username and password; if the receiving host logs in with the publisher's credentials, the two clients fight over one session and knock each other offline. The ID is how the broker tells sessions apart, which is why device roles and application roles get different IDs, as laid out in MQTT client ID device versus application roles explained.
Counting sessions and ports: one Temperature publisher, one subscriber #
The case is a typical cell build: one edge Node-RED device publishes a Temperature reading on a repeating timer, and one plant-side Node-RED host subscribes to that single topic.
Inputs:
- One publishing client: the edge device's
mqtt outnode. - One subscribing client: the receiving host's
mqtt innode, subscribed to Temperature. - Broker listener: port 8883 with TLS enabled; 1883 is the plaintext default.
- Documented rules: an MQTT connection always runs between one client and one broker, clients never connect to each other, and the broker accepts one connection per client ID.
Rule in words: on the broker path, every session is a client dialing the broker, so sessions on the wire equal clients and the publisher holds exactly one address. On the direct path, every session is one point-to-point link, so sessions equal consumers and each link's address and port live in the sender's tcp out node.
Arithmetic. Broker path: the publisher opens 1 session to the broker and the subscriber opens 1 session to the same broker, so 1 + 1 = 2 client sessions on the wire; listening ports on either Node-RED host = 0; addresses the publisher holds = 1, the broker. Direct path: tcp out opens 1 session to the receiver's listener, so 1 link = 1 session; listening ports on the receiving host = 1; the publisher holds 1 address plus the chosen port. Now land a second consumer: broker path 2 + 1 = 3 sessions and the publisher's flow is untouched; direct path 1 + 1 = 2 sessions, one second tcp out to build, and 2 addresses stored at the publisher.
Result: at one sender and one receiver the builds are equals — each is one dial-out deep. The counts separate only when the second consumer lands: one new subscriber on the broker path, one new sender-side edit per consumer on the direct path.
Decision: more than one consumer, or any endpoint that might be readdressed, and the broker path wins — its publisher-side cost stays at one address and zero edits. Exactly one fixed pair you own at both ends: build the direct link, because its extra process count of one broker buys nothing there.
Where each path fails #
- Stuck at Connecting on the TLS port: a plaintext client against a TLS listener, or a failed handshake. Trace the hop from the client's connection status.
- Never connects at all: wrong broker address, wrong port, or the broker process is down.
- Connects, drops, reconnects: another client is holding this client ID.
- Connected but no values: the subscribed topic differs from the published topic. MQTT raises no error for this; the subscriber is simply silent.
- Values stop after a broker restart: the subscriber's session did not come back the way its settings intend — see Why an MQTT subscriber stops receiving after a broker restart.
tcp outshows Disconnected: the receiver is not deployed, or its address or port does not match.- Garbled or split readings on the direct path: the framing rule on
tcp indoes not match the bytes the sender streams.
The decision #
Commit by consumer count and address stability, not by protocol taste.
-
One publisher, one receiver, both addresses fixed and owned by your team, and a payload simple enough for a delimiter or a fixed length: build
tcp outtotcp in. It is two nodes, there is no broker process to install, secure, restart or back up, and the whole link sits in one flow. -
A second consumer now or later, an endpoint that may be replaced or moved, more than one publisher, or a link that leaves the machine network: build the broker path. The publisher holds one address forever, consumers filter by topic, TLS and per-client credentials come with the protocol, and growth costs one new client session instead of one new sender-side edit.
-
A cloud MQTT endpoint is itself a broker, so the sender is still an
mqtt outclient there; when the only open path to it is the HTTPS port, MQTT rides that port with ALPN, as explained in Why MQTT over port 443 to a cloud needs ALPN. Raw TCP has no role in that hop. -
The broker does not need a new machine of its own; one of the cell's existing edge PCs can host it for the rest, as sized in When one edge PC can host the MQTT broker for the rest.
Questions asked
Does the direct TCP link encrypt anything?
No. A tcp out stream carries whatever bytes the flow feeds it, with no TLS at the protocol level. MQTT with the TLS option enabled encrypts on the broker's port. If the link crosses cell boundaries, use the broker path with a certificate the client actually verifies, or wrap the raw stream in a site-approved encrypted tunnel and treat the tunnel's endpoints as the trust boundary.
What happens when two clients share one client ID?
The broker treats them as one client, so the second connection displaces the first and both nodes flap between Connecting and Connected without ever settling. Give every client its own client ID and its own username and password. The broker keeps exactly one live session per ID, which is why the publisher's login never belongs on the receiving host.
Can I add a second publisher to the same broker later?
Yes, and nothing on the first publisher changes. The new publisher connects with its own client ID and credentials and publishes its own topics; existing subscribers add subscriptions to those topics when they want the data. That is the decoupling the broker buys: endpoints join and leave without edits anywhere else, which a point-to-point TCP link cannot do.
Do I need to open a port on the sender's firewall for either path?
No. In both builds the sending Node-RED dials out, so nothing has to listen on it. On the broker path the only listener is the broker itself, which means one port opened on one host no matter how many clients connect. On the direct path each receiving host opens one listening port per link.