top of page

What is MQTT (Message Queuing Telemetry Transport)?

Oct 26
10 min read

Updated: Oct 27

What is MQTT (Message Queuing Telemetry Transport)?

 

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol that lets devices and applications publish information to a broker, which forwards it to interested subscribers. It is useful for sensor readings, home automation and remote monitoring because the sender does not need a separate connection to every recipient. Its delivery settings govern messages, however, not whether a machine successfully carries out a command.

 

A temperature sensor can publish one reading and let a dashboard, automation controller and logging service each receive it. That separation is MQTT’s real advantage. A small message size helps, but reliable operation still depends on the network, broker, session configuration and application design.

 

How does MQTT work?

 

An MQTT client can publish, subscribe or do both. The broker is the server that accepts client connections and routes messages according to subscriptions. It does not normally interpret a temperature reading or decide what a thermostat should do. Those are application responsibilities. Our message broker guide explains the broader role of that intermediary.

 

  1. A dashboard connects to the broker and sends a SUBSCRIBE packet containing a topic filter, such as home/+/temperature.

  2. The broker returns SUBACK, confirming the subscription result and granted delivery level.

  3. A sensor connects and publishes a message on home/kitchen/temperature. Its payload might contain 21.4, with the unit defined by the application.

  4. The broker matches the topic against subscriptions and sends the message to eligible subscribers. Delivery to each subscriber is a separate exchange.

  5. Each receiving application decides whether to display, store or act on the value. If an action matters, it reports the outcome through an application-level response.

 

The publisher need not know the subscribers’ addresses. Subscribers need not be online at the same instant for every design, but receiving missed messages requires suitable session and delivery settings. A broker is also an operational dependency: losing it can interrupt communication even when the broadband connection is working.

 

The infographic below follows the subscription and publication paths, then separates delivery reliability, retained state and loss detection. The equipment is illustrative; MQTT is a software protocol, not a particular type of physical cable or server.

 

What is MQTT (Message Queuing Telemetry Transport) infographic explaining the mechanism, key stages and practical limits.

 

Topics, filters and payloads

 

A topic is a case-sensitive, hierarchical name used to route a message. A topic filter describes the names a subscriber wants. Forward slashes separate levels; they do not create directories on disk. A payload is the application data. MQTT can carry binary data or text, including JSON, but the communicating applications must agree how to interpret it.

 

Topic filter

What it matches

home/kitchen/temperature

That exact topic

home/+/temperature

One intervening level, such as kitchen or bedroom

home/#

The home topic and its descendant levels

 

Wildcards belong in subscription filters, not published topic names. The single-level + occupies one complete level; the multi-level # must occupy the final level. A broad subscription starting with a wildcard does not automatically match topics beginning with $. Design topic names and permissions together so a sensor can publish its own readings without gaining permission to control unrelated equipment.

 

What do MQTT QoS 0, 1 and 2 mean?

 

Quality of Service, or QoS, specifies the MQTT delivery exchange between one sender and one receiver. OASIS’s MQTT 5.0 standard, published on 7 March 2019, defines three levels. The publisher-to-broker exchange and broker-to-subscriber exchange can use different levels, so publishing at QoS 2 does not force every subscriber to receive at QoS 2.

 

Level

Exchange and meaning

Practical trade-off

QoS 0

PUBLISH without MQTT acknowledgement; at most once

A reading may be lost. Useful when a fresh reading soon replaces it.

QoS 1

PUBLISH and PUBACK; at least once

Duplicates are possible. Applications must tolerate repeat delivery.

QoS 2

PUBLISH, PUBREC, PUBREL and PUBCOMP; exactly once within that delivery exchange

More protocol state and acknowledgement traffic; support must be checked.

 

A subscriber requests a maximum QoS and the broker grants an available level. The incoming publication and granted subscription level constrain onward delivery. Check broker support and quotas rather than assuming every managed platform implements all three levels.

 

Why an acknowledgement does not prove a command worked

 

A broker acknowledging a message does not prove the subscriber received it, wrote it to a database or opened a valve. Even a completed subscriber-side MQTT exchange is not an atomic transaction with the external world. A consumer could acknowledge and then crash before completing its work.

 

For consequential commands, give each request a unique application identifier, make repeat processing safe, record completion and return an explicit result. Idempotency is particularly useful here: asking for a target state such as set temperature to 19°C is generally easier to retry safely than an instruction such as increase temperature by 1°C. Both still need application-specific validation.

 

Retained messages, persistent sessions and Last Wills are different

 

Retained messages provide a snapshot

 

A retained publication asks the broker to keep the latest retained value for that topic and make it available to later matching subscriptions, subject to the protocol version and subscription options. It is useful for a device’s last reported state. It is not an event history, and last reported does not mean current.

 

Put an observation timestamp in the payload and check freshness before acting. MQTT 5 Message Expiry can limit how long a publication remains useful. Avoid retaining one-off actions such as unlock now: a device subscribing later could receive an old command. Mosquitto’s client documentation also shows that a retained publication with an empty payload clears the retained message on that topic.

 

Persistent sessions preserve eligible delivery state

 

Session state belongs to a client identity. It can include subscriptions and unfinished or queued QoS 1 and QoS 2 deliveries. In MQTT 5, Clean Start controls whether an existing session is discarded at connection, while Session Expiry controls how long state survives after disconnection. An absent Session Expiry property defaults to zero, so offline persistence must not be assumed.

 

MQTT 3.1.1 uses Clean Session instead. Broker storage policy, queue limits, expiry, failures and administrative actions all matter. Session continuity is not a promise of unlimited storage or crash-proof recovery. Nor can a broker preserve readings that a disconnected sensor never managed to send; that needs buffering on the sensor or gateway.

 

Keep Alive detects an inactive connection

 

With a non-zero Keep Alive interval, a client must send MQTT control traffic within that interval. When it has nothing else to send, it sends PINGREQ and expects PINGRESP. Ordinary MQTT traffic can satisfy the activity requirement, so it is misleading to say every active client must always send a separate ping on a fixed schedule.

 

The MQTT 5 rule requires the broker to close a connection if no client control packet arrives within 1.5 times the effective Keep Alive interval. For an illustrative 60-second interval, that threshold is 90 seconds. This is a connection inactivity rule, not a guarantee that an alarm reaches a human within 90 seconds. Detection may happen earlier through a network error, and further delivery can take time.

 

A Last Will lets the broker report a lost client

 

A client can register a Will when connecting, for example an offline notification on a status topic. The broker can publish that message when the connection ends in qualifying circumstances. The failed device is not transmitting its own farewell. MQTT 5’s Will Delay and session lifetime affect timing, and a normal disconnect normally suppresses the Will. A broker failure can itself delay the notification.

 

MQTT versions, TCP, WebSockets and encryption

 

MQTT 3.1.1 and MQTT 5.0 retain the broker-based model but differ in features and packet details. Version 5 adds capabilities including richer reason codes, message expiry, topic aliases and more explicit session controls. A topic alias can reduce repeated topic-name overhead after it is established on a connection. Client and broker capabilities must agree.

 

MQTT commonly runs over a persistent TCP connection, with TLS added for transport security. MQTT over WebSockets is useful where a browser or network intermediary needs WebSocket transport; it still carries MQTT messages and requires compatible broker support. MQTT-SN is a separate related protocol aimed at sensor networks beyond conventional TCP/IP connectivity. Do not treat it as merely switching ordinary MQTT to UDP.

 

TCP preserves an ordered byte stream, but packet loss can delay subsequent data while recovery takes place. A connected socket also does not establish that application data is fresh. MQTT is therefore useful for timely telemetry without being a hard real-time control guarantee.

 

Securing an MQTT broker

 

Encryption, authentication and authorisation solve different problems. TLS protects a connection and allows server identity verification; credentials or client certificates identify a client; topic permissions control what it can publish and receive. TLS terminating at a broker does not by itself provide end-to-end encryption between publishing and subscribing applications.

 

  • Use verified TLS for traffic crossing untrusted networks. Do not disable certificate checks to make an error disappear.

  • Give devices separate identities and the smallest publish/subscribe permissions they need.

  • Keep control topics separate from general telemetry and validate command payloads, identifiers and expiry.

  • Set sensible connection, message-size and queue limits. Monitor broker health and storage rather than assuming persistence is unlimited.

  • Plan credential rotation, software updates and recovery after power loss. Treat retained payloads and queued commands as stored operational data.

 

Common listener ports are 1883 for unencrypted MQTT and 8883 for MQTT over TLS, but the configured listener determines both the port and security behaviour. A port number alone proves nothing. Eclipse Mosquitto’s broker configuration manual documents listener, authentication, topic access and persistence controls; defaults and supported settings must be checked for the installed version.

 

Does MQTT need fast broadband?

 

Many telemetry workloads need little capacity. Their reliability can depend more on stable WiFi, sensible reconnect behaviour, broker availability and delay under load than a higher headline broadband tier. A local broker serving local devices can keep that communication on the LAN. Cloud services and off-site subscribers add WAN dependencies.

 

For a cloud broker, the path includes the sensor, local network, router, access network, ISP, wider route and broker, followed by a separate path to each subscriber. A congested upload can delay tiny messages behind large transfers. Bufferbloat explains why a small telemetry stream can become sluggish while a backup saturates the connection.

 

Techie Broadband calculation: payload rate and fan-out

 

Consider 100 sensors, each publishing a 100-byte payload every 10 seconds. These are illustrative assumptions, not measurements. They produce 100 × 100 ÷ 10 = 1,000 payload bytes per second, or 8,000 bits per second: 8 kbit/s. Over a 30-day month that is 2.592 GB of payload using decimal units.

 

Location or delivery pattern

Illustrative payload traffic

Sensors to one broker

8 kbit/s aggregate

Broker forwards every message to one subscriber

8 kbit/s broker egress

Broker forwards every message to ten subscribers

80 kbit/s broker egress

Local broker, all consumers on the same LAN

No WAN payload traffic for these local exchanges

 

These figures exclude topic names, MQTT headers, acknowledgements, TCP/IP, TLS, connection setup, retransmissions and unrelated traffic. Cloud billing and interface counters may count different things. The fan-out occurs at the broker: ten remote subscribers do not automatically make the sensor publish ten copies. Broker placement determines which network links carry those copies.

 

For a home-hosted broker, clients connecting from outside need a reachable and properly secured route. CGNAT can prevent straightforward unsolicited inbound IPv4 connections. Outbound connections to a remote broker are a different case and do not normally require inbound port forwarding. Check the actual network design rather than exposing an unauthenticated broker to fix connectivity.

 

A safe local MQTT test

 

The following demonstration assumes an installed Mosquitto broker already configured to accept local test connections on 127.0.0.1:1883, plus its command-line clients. It does not configure a public listener or provide a production security setup. These commands use MQTT 5 and a disposable topic. Their options have been checked against the official client manuals; no live test result is claimed.

 

  1. Start the subscriber in one terminal before publishing. It prints the topic with the received payload and exits after one message.

  2. Run the publisher in a second terminal. The retained flag stores this disposable reading for the next subscriber.

  3. Run the subscriber again to check retained delivery. The reading should arrive without a new publication if the broker accepted and retained it.

  4. Clear the disposable retained value when finished using the final command. Do not use this command on an operational topic without intending to remove its retained state.

 

mosquitto_sub -h 127.0.0.1 -p 1883 -V mqttv5 -t 'techie/demo/temperature' -q 1 -v -C 1

 

mosquitto_pub -h 127.0.0.1 -p 1883 -V mqttv5 -t 'techie/demo/temperature' -q 1 -m '21.4' -r

 

mosquitto_pub -h 127.0.0.1 -p 1883 -V mqttv5 -t 'techie/demo/temperature' -q 1 -n -r

 

A refused connection means the assumed broker/listener is unavailable or blocked. An authorisation error requires the correct local credentials and permissions. Successful receipt verifies this small local path only; it does not test cloud reachability, device power-loss recovery or broker persistence after restart.

 

Troubleshooting missing, duplicate or delayed messages

 

  1. Establish the scope. Does communication fail locally too, or only through the WAN? Compare a wired local client with the affected device.

  2. Check broker logs, listener address, port, TLS trust and authentication. Distinguish a failed connection from a rejected subscription or publication.

  3. Compare the exact topic name with the subscription filter, including case and empty levels. Verify read and write permissions separately.

  4. Check client identifiers. Two connections using the same identity can cause takeover and repeated disconnections.

  5. For missing offline messages, inspect the granted QoS, Clean Start or Clean Session, Session Expiry, queue limits and broker storage. Check whether the publisher actually sent the data before it lost connectivity.

  6. For stale state, inspect payload timestamps, retained flags and expiry. A newly delivered message can contain an old observation.

  7. For duplicates, inspect application identifiers and retry handling. Do not assume QoS 1 makes processing unique.

  8. For delay, compare idle and loaded behaviour, inspect WiFi loss and router queues, and check broker CPU, storage and subscriber processing. Avoid blaming broadband capacity before locating the bottleneck.

 

When should you choose MQTT?

 

Requirement

Useful starting point

Many devices publish readings to several consumers

MQTT’s broker-based publish/subscribe model is a strong fit.

A straightforward request to fetch or update a web resource

HTTP may be simpler, especially with existing web APIs.

Browser-to-server bidirectional transport

WebSockets supplies transport; MQTT over WebSockets adds MQTT messaging semantics.

Constrained devices using a resource-oriented model

Investigate CoAP, including its transport and security choices.

Rich enterprise messaging or queue workflows

Compare AMQP and the actual broker’s routing and delivery features.

 

Choose according to delivery semantics, client support, failure handling and operations. A protocol labelled lightweight is not automatically the smallest total deployment: TLS handshakes, connection count, stored state and monitoring still consume resources.

 

MQTT questions answered

 

Does MQTT work without the internet?

 

Yes, when the broker and communicating clients are reachable locally and the application has no other internet dependency. A cloud-hosted broker requires a working route to that service. Local MQTT does not make a cloud-dependent automation system fully offline-capable.

 

Is MQTT a message queue?

 

Its central model is publish/subscribe. Brokers can queue eligible deliveries for sessions, but that does not make every topic a durable work queue with competing consumers. MQTT 5 shared subscriptions can distribute matching publications among members of a group; broker support and failure behaviour still need checking.

 

Does MQTT guarantee the order of every event?

 

Do not assume a single global order across publishers, topics and reconnects. If order matters to your application, include sequence numbers and source identifiers, define how duplicates and late arrivals are handled, and test the chosen broker and client configuration.

 

Can MQTT send large files?

 

It can carry binary payloads, but client and broker size limits, memory, queueing and expiry make large files a separate design question. Often it is more practical to transfer a file through a suitable file service and publish a reference, integrity information and completion event through MQTT.

 

Key takeaway

 

MQTT makes it easier to separate devices that produce information from applications that consume it. Build reliability around the whole path: secure connections, deliberate topic permissions, appropriate QoS, bounded persistence, freshness checks and explicit application outcomes. The message reaching a broker is one stage of that journey, not proof that the intended result happened. The broadband terminology guide provides the related networking foundations.

 
 
UK Techie Broadband Providers
bottom of page