MQTT QoS explained

3 mins read

IoT networks have one job – to get the message from point A (e.g. an IoT device) to point B (e.g. an IoT dashboard). Whatever the application, ensuring the business collects the right information from IoT devices and vice versa is essential.  Where the MQTT (Message Queue Telemetry Transport) protocol is concerned, the guarantee of delivery is defined by QoS (Quality of Service).

In this article, you’ll learn how, where and when to use MQTT QoS and which levels are right for your own IoT applications.

MQTT QoS levels

MQTT and MQTT-SN (MQTT for sensor networks) support multiple levels of QoS for guaranteeing message delivery.

QoS -1 – fire and forget

QoS -1 is ideal for low-power non-critical applications where it doesn’t matter if every message gets to where it’s going. By not making a hard connection with the broker and receiving no acknowledgement, considerably less power is used to complete the transaction.

QoS -1 key features:

  • Only available for devices using MQTT-SN
  • Does not require an MQTT connection to be established
  • No acknowledgement from the recipient
  • Not retried by the sender
  • Analogous to QoS 0 by the time it reaches the broker

When to use QoS -1:

  • Ideal for power constrained Things to minimise time on air
  • Minimise messaging cost
  • OK if message delivery is not critical e.g. data sent frequently

QoS 0 – at most once

QoS 0 is used to ensure that a message reaches its destination no more than once. Unlike QoS -1, this method requires an MQTT connection meaning it is less efficient in terms of power.

QoS 0 key features:

  • Best effort message delivery
  • No acknowledgement from the recipient
  • Not retried by the sender
  • Not queued by the broker for disconnected clients with a valid subscription to the topic

When to use QoS 0:

  • As QoS-1 except a CONNECT is necessary so not as efficient for power or message consumption

QoS 1 – at least once

QoS 1 is used when message delivery is critical. This is achieved by queueing messages until the subscriber is able to receive it.

QoS 1 key features:

  • Guarantees that a message is delivered at least one time to the recipient. 
  • Sender stores the message until it receives a PUBACK from the recipient
  • Messages may be sent or delivered multiple times.

When to use QoS 1:

  • Use when you have to receive every message, but make sure you handle duplicates
  • Use if you want messages to be queued on the broker for delivery to offline Clients
  • Use when the overhead of QoS 2 is too high

QoS 2 – exactly once

QoS 2 is used when the message needs to arrive once and only once. This level is used when delivery essential.

QoS 2 key features:

  • QoS 2 is the safest and slowest quality of service level
  • Guarantees that each message is received only once by the intended recipients by using at least two request/response flows (a four-part handshake) between the sender and the receiver.

When to use QoS 2:

  • Use if message delivery is critical and duplicate data is harmful to subscribers

MQTT QoS downgrade

In cases where there are many devices on the network, different levels of QoS might be needed. To achieve this, MQTT allows downgrading of QoS level at the subscriber node. The result of this is that the QoS for a message that is published does not have to be the same as the QoS for a message that is received.

QoS is defined by the original publisher, but when the broker then delivers the message on to subscribers, the lower of the PUBLISH QoS and the QoS defined during the SUBSCRIBE is used.

Conclusion

Understanding QoS levels and the impact they have on the network are essential to building an effective and efficient MQTT/MQTT-SN-based solution. Using the wrong level could leave you with duplicates, missed messages or even a flat battery.

Thingstream enables low-power MQTT-SN communication over cellular networks as well as MQTT integration for IP-based devices. For more information about Thingstream, please get in touch.

Globally connect your business

Get in touch with Thingstream to bring global IoT connectivity to your devices.

Get started