MQTT · Study deck

MQTT QoS Levels

Picture a cold room that sends routine temperatures and a rare warm alarm.

Broker Bex is your guide for this deck.

Broker Bex tests temperature and alarm message delivery by disconnecting a broker test link.
iotclass.org

After studying this chapter

Learning objectives

The right delivery contract depends on what losing or repeating a message would do.

  • Different message families can need different delivery promises.The cold room sends replaceable routine temperatures and a rare warm alarm whose loss or repetition can change a safety decision.
  • QoS 1 retries require duplicate-safe consumers.A lost PUBACK can lead to another PUBLISH, so an event identifier or desired-state command must make repeated handling safe.
  • QoS 2 can control duplicate delivery on one protocol leg.Its longer handshake retains packet-identifier state at both peers until completion, adding packets, storage, and recovery work to the exchange.
  • A physical outcome needs separate application evidence.The broker can acknowledge a valve command without proving valve movement, so the device must report its result or final state.

I am pricing the delivery promises for a cold room that sends routine temperatures and a rare warm alarm. I need each promise to protect its decision without hiding the cost of retries or the need for a device result.

iotclass.org

Major section

Start With The Consequence Of Losing One Message

A routine temperature reading and a rare alarm protect different decisions.

  • A fresh routine sample can replace a lost temperature reading.The cold-room decision may tolerate one missing value when the next sample arrives soon and the dashboard shows whether readings remain fresh.
  • A missing alarm can change the response to a temperature problem.The rare warm alarm has different loss consequences from routine readings, so both families need their own documented delivery promises.
  • Repeated events need safe handling in the receiving application.An important door-open event can use QoS 1 with an event identifier, allowing the consumer to recognize a repeat during retry.
  • Failure tests must preserve the promised application outcome.Link cuts, repeated acknowledgements, broker restarts, and receiver reconnects expose losses, repeats, and delays that must match the cold-room policy.

I watch the cold room send its routine readings and then one warm alarm. I cut the link and reconnect the receiver to see whether losses, repeats, and delays leave the final cold-room state consistent with the chosen promise.

iotclass.org

Major section

Topic promises, safe commands, and state readback

Message-family documentation connects QoS with useful evidence.

  • Topic documentation connects delivery policy with tolerated loss and delay.The temperature topic uses QoS 0 and maximum staleness of 30 seconds to align firmware, broker policy, and dashboard expectations.
  • Event identifiers make repeated alarm deliveries recognizable.The alarm topic declares QoS 1 and requires an event identifier, giving the consumer evidence for suppressing duplicates after a retry.
  • Desired-state commands make repeated handling safer than toggle actions.Replacing toggle_relay with set_relay_state=on avoids switching the relay twice when a QoS 1 retry brings the same command back.
  • State readback closes the gap between delivery and device outcome.A command identifier and broker acknowledgement still leave the physical result unproven until the device reports its accepted or rejected state.

I am writing the cold-room topics on my board. I put the temperature freshness limit beside the alarm event identifier, then keep the device result separate from the broker receipt.

iotclass.org

Major section

QoS Is Hop-by-Hop State

This sequence shows the low-state delivery baseline before acknowledgement and retry are added.

  • The first PUBLISH travels from publisher to broker without acknowledgement.The QoS 0 sequence has no return packet on that leg, leaving the publisher without protocol evidence that the broker received the publication.
  • The next PUBLISH travels from broker to subscriber without acknowledgement.The second delivery leg also provides no QoS 0 receipt confirmation, so broker receipt alone cannot establish delivery to the subscribing application.
  • A lost QoS 0 publication can disappear silently.Neither leg confirms receipt in this sequence, making the low-state path suitable for replaceable telemetry rather than an unsupported must-arrive promise.
  • Higher QoS levels add stored exchanges separately on each delivery leg.Publisher and subscriber delivery can use different effective QoS levels, so the broker handshake cannot establish an end-to-end physical or business outcome.
MQTT QoS 0 sequence with one PUBLISH and no acknowledgement
MQTT QoS 0 sequence with one PUBLISH and no acknowledgement
iotclass.org

Major section

Choose QoS for a Valve Command and a Gauge

This sequence connects a replaceable gauge reading with the cost of its delivery promise.

  • The one-way PUBLISH path gives the gauge no receipt confirmation.The QoS 0 sequence contains no acknowledgement, so a missing gauge sample has no return packet that could prove successful receipt.
  • The next gauge value can make one lost sample acceptable.At 60 readings per minute, the pressure gauge supplies a fresh value one second later, allowing a message-family policy to tolerate loss.
  • The rare valve command needs a separate duplicate-handling decision.A repeated OPEN action can be unsafe unless the application handles its command identifier idempotently, even when important telemetry shares the device.
  • More handshake state leaves the physical action unproven.QoS 2 adds packets and stored session state for duplicate control at the MQTT layer, while the valve outcome still requires device evidence.
MQTT QoS 0 sequence with one PUBLISH and no acknowledgement
MQTT QoS 0 sequence with one PUBLISH and no acknowledgement
iotclass.org

Major section

Packet identifiers, reconnects, and retained state

Retained messages and unfinished handshakes are different broker responsibilities.

  • Packet identifiers connect acknowledgements with the correct unfinished publication.Identifier 42 belongs to one in-flight exchange; using the same number for two unfinished exchanges would confuse which publication an acknowledgement completes.
  • A completed exchange allows its packet identifier to be reused.Identifier 42 can be used again after its QoS exchange finishes, keeping packet-handshake identity distinct from an application command identifier.
  • Session settings determine which state survives reconnect.The valve tests need the chosen clean-start and expiry behaviour because a reconnect can change retained state and queued-message handling at the broker.
  • A retained message does not upgrade its delivery handshake.A retained QoS 0 state remains a QoS 0 delivery choice; broker retention and unfinished handshake state are separate responsibilities.

I send the valve command with packet identifier 42 and lose its PUBACK. I keep the unfinished exchange on my board while checking the retry, reconnect settings, and the separate final valve state.

iotclass.org

Activity 1 · Predict

✎ Lose the acknowledgement

I want you to price the retry before you promise that the valve is safe.

On paper, send a QoS 1 valve command and lose its PUBACK. Predict what a repeated PUBLISH can do. Write one way to make repeated handling safe, then name evidence that proves the valve’s final state.

3 minutes · Pen and paper · Answer: Activity 1

Your answer
iotclass.org

Major section

Summary

A reliable application combines delivery contracts with safe handling and outcome evidence.

  • QoS 0 reduces acknowledgement work for replaceable telemetry.A gauge value arriving each second can replace a lost sample, avoiding extra radio and broker work when the policy tolerates that loss.
  • QoS 1 supports important events when consumers safely handle repeats.The door-open event needs delivery retries and an event identifier or idempotent processing so another delivery does not repeat the harmful effect.
  • QoS 2 adds duplicate-control state for narrowly justified delivery needs.Its multi-step handshake costs packets, storage, and recovery logic, so frequent replaceable gauge samples need a different review from rare valve commands.
  • A device result must confirm the physical or business outcome.The broker/client delivery step cannot prove that a pump started, a door locked, or a technician responded to the requested action.

I return to the gauge sending one value each second and the valve waiting for a rare OPEN command. I can justify different delivery contracts, but I still need a device result before calling the valve action complete.

iotclass.org

Deck summary

Key takeaways

QoS policy belongs to each message family and must survive failure testing.

  • Loss consequences determine the delivery promise for each message family.The cold room can tolerate a missing routine reading while a rare warm alarm needs a policy that protects the response decision.
  • QoS 1 retries make duplicate-safe application handling essential.A lost PUBACK can repeat a valve command, so desired state or command identity must prevent repeated handling from causing an unsafe action.
  • Sessions and broker limits shape what an offline subscriber receives.Session configuration, queued-message policy, retained messages, and reconnect behaviour determine the offline result rather than the publication QoS label alone.
  • Application acknowledgement supplies evidence beyond protocol delivery.A final state update or application result establishes the device outcome after the broker handshake has completed only its own delivery leg.

I am reviewing the cold-room record after a disconnect and reconnect. I look for the chosen message-family promise, safe duplicate handling, offline behaviour, and the application evidence that closes the outcome question.

iotclass.org

Retrieval practice

Recall check 1 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q1A battery-powered sensor publishes a replaceable temperature reading every few seconds. Which MQTT QoS choice is usually the best starting point?

AQoS 0.
BQoS 2.
CQoS 1.
DThe alarm QoS.
Show answer

Answer: A For replaceable telemetry, occasional loss is tolerable and avoiding acknowledgements reduces radio and broker work.

iotclass.org

Retrieval practice

Recall check 2 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q2A device currently publishes the command 'toggle_relay' with QoS 1. Sometimes a retry causes the relay to switch twice. What is the best design fix before reaching for QoS 2?

AUse QoS 0 so duplicate commands cannot occur.
BApply QoS 2 across the device.
CUse an idempotent desired-state command.
DSuppress matching payloads at the broker.
Show answer

Answer: C Replacing toggle_relay with a desired-state command such as set_relay_state=on removes the harm from duplicates and gives the system clearer evidence.

iotclass.org

Retrieval practice

Recall check 3 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q3A controller publishes a QoS 2 command to an MQTT broker. The broker completes the QoS 2 handshake with the controller. What has been proven?

AThe actuator definitely completed the physical action exactly once.
BAll subscribers received the command at QoS 2, regardless of their subscription settings.
CThe command can be treated as safe even if it is non-idempotent and no application result is recorded.
DThe broker-side protocol exchange for that delivery leg completed.
Show answer

Answer: D MQTT QoS is protocol delivery evidence, not proof that the physical action happened.

iotclass.org

Print reference

Answers

Answer key.

  1. A · For replaceable telemetry, occasional loss is tolerable and avoiding acknowledgements reduces radio and broker work.
  2. C · Replacing toggle_relay with a desired-state command such as set_relay_state=on removes the harm from duplicates and gives the system clearer evidence.
  3. D · MQTT QoS is protocol delivery evidence, not proof that the physical action happened.
iotclass.org

Print reference

Activity 1 answer

Model answer.

Predict: The payload may be delivered again. A command identifier with duplicate suppression, or an idempotent desired-state command, can make repeated handling safe. Application acknowledgement or state readback must establish the valve’s actual result.

iotclass.org