Packet overhead: 4 messages per side (8 total) Delivery guarantee: Exactly once (no duplicates, guaranteed delivery) Use case: Critical commands (unlock door, dispense medication)
Why 4 steps?
PUBLISH - βHereβs a messageβ
PUBREC - βI received it, but havenβt processed yetβ
PUBREL - βOK, you can process it nowβ
PUBCOMP - βDone processing, weβre completeβ
Show code
{const container =document.getElementById('kc-mqtt-qos-1');if (container &&typeof InlineKnowledgeCheck !=='undefined') { container.innerHTML=''; container.appendChild(InlineKnowledgeCheck.create({question:"A hospital's medication dispensing system uses MQTT to send commands to drug cabinets. When a nurse requests medication, the system publishes 'dispense 50mg morphine' to the cabinet. What could go wrong with QoS 1, and which QoS should be used?",options: [ {text:"QoS 1 could lose the command; use QoS 0 for faster delivery",correct:false,feedback:"QoS 0 has NO delivery guarantee - the command could be lost entirely. For critical medication dispensing, losing commands is unacceptable."}, {text:"QoS 1 could duplicate the command (dispense twice); use QoS 2 for exactly-once delivery",correct:true,feedback:"Correct! QoS 1 guarantees 'at least once' delivery, but if the PUBACK is lost, the command may be resent - potentially dispensing double the medication. QoS 2's four-way handshake ensures exactly-once execution."}, {text:"QoS 1 is fine; duplicates can be handled by checking medication inventory",correct:false,feedback:"Relying on inventory checks after dispensing is dangerous. A duplicate dispense of a controlled substance like morphine could cause patient harm."}, {text:"QoS 1 is fine; the cabinet can ignore duplicate commands",correct:false,feedback:"Medication cabinets typically don't maintain command history to detect duplicates. The protocol must prevent duplicates."} ],difficulty:"hard",topic:"mqtt-qos" })); }}
1189.4 QoS Trade-off Analysis
WarningTradeoff: QoS Level Selection
Option A: Use QoS 0 (fire-and-forget) for all telemetry data Option B: Use QoS 1/2 for guaranteed delivery with acknowledgments
Decision Factors:
Factor
QoS 0
QoS 1
QoS 2
Message overhead
1 packet
2 packets
4 packets
Battery impact
Lowest
Medium (+25%)
Highest (+75%)
Delivery guarantee
None
At-least-once
Exactly-once
Duplicate messages
No
Possible
Never
Network traffic
Baseline
+12%
+29%
Broker load
Lowest
2x
4x
Choose QoS 0 when:
High-frequency sensor readings where next value supersedes lost ones
Battery life is critical priority
Data redundancy exists (multiple sensors)
Network is generally reliable
Choose QoS 1 when:
Important notifications and alerts
Audit logging where completeness matters
Commands where idempotent execution is safe
Choose QoS 2 when:
Financial transactions or billing events
Security-critical commands
State changes where duplicate execution is dangerous
Default recommendation: QoS 0 for 95%+ of IoT telemetry; QoS 1 for alerts; QoS 2 only when exactly-once is required
1189.5 Common Misconception: Always Use QoS 2
WarningMyth: βAlways Use QoS 2 for Important Dataβ
The Misconception: Many developers assume that βimportantβ IoT data should always use QoS 2 because it provides the strongest guarantee.
The Reality: QoS 2 has a 4x message overhead compared to QoS 0 and can reduce battery life by 70-80% in battery-powered devices.
Real-World Example - Smart Agriculture Deployment:
A large-scale agricultural IoT deployment initially configured 10,000 soil moisture sensors with QoS 2 for all readings because the data was considered βcritical for irrigation decisions.β
Results after 3 months:
Battery life: 4.2 months (expected 12-18 months with QoS 0)
Network congestion: 40% of messages delayed >10 seconds
Figure 1189.1: QoS comparison for 50-sensor smart building deployment
1189.6.7 Design Recommendation
TipRecommendation for This Scenario
Use QoS 0 for this deployment because:
Temperature data is non-critical - If one reading is lost, the next arrives soon
Redundancy from frequency - 288 readings/day means losing a few has minimal impact
Lowest bandwidth cost - Saves 5.7 MB/month vs QoS 2
Lowest broker load - 4x fewer messages than QoS 2
When would QoS 1/2 be justified?
Scenario
Recommended QoS
Rationale
Temperature readings every 5 min
QoS 0
High frequency, non-critical
Fire alarm trigger
QoS 1
Critical alert, duplicates acceptable
HVAC setpoint command
QoS 1
Important, duplicate wonβt cause harm
Door lock/unlock command
QoS 2
Security-critical, exactly once
1189.6.8 Cost Implications (AWS IoT Core Pricing)
QoS Level
Monthly Messages
Cost @ $1/million
Annual Cost
QoS 0
432,000
$0.43
$5.18
QoS 1
864,000
$0.86
$10.37
QoS 2
1,728,000
$1.73
$20.74
Key insight: QoS 2 costs 4x more than QoS 0 for the same sensor data.
Show code
{const container =document.getElementById('kc-mqtt-qos-2');if (container &&typeof InlineKnowledgeCheck !=='undefined') { container.innerHTML=''; container.appendChild(InlineKnowledgeCheck.create({question:"Your IoT fleet has 5,000 battery-powered sensors sending temperature readings every 30 seconds. You're choosing between QoS 0 and QoS 1. Each QoS 1 message requires 2 packets vs 1 for QoS 0. If sensor battery life with QoS 0 is 2 years, what's the approximate battery life with QoS 1?",options: [ {text:"2 years (same as QoS 0)",correct:false,feedback:"QoS 1 requires transmitting twice as many packets. Each transmission consumes battery power."}, {text:"1.5 years (25% reduction)",correct:false,feedback:"The overhead is more significant. QoS 1 doubles the packet count."}, {text:"1-1.2 years (40-50% reduction)",correct:true,feedback:"Correct! QoS 1 approximately doubles radio transmission overhead, translating to roughly 40-50% battery life reduction."}, {text:"6 months (75% reduction)",correct:false,feedback:"This overestimates the impact. The actual impact is closer to 40-50% reduction."} ],difficulty:"medium",topic:"mqtt-qos" })); }}
The Mistake: Using clean_session=True without understanding that the broker discards all stored state, causing missed messages after reconnection.
Why It Happens: Many examples use clean_session=True for simplicity. When a device reconnects after network loss, it must re-subscribe, and messages published during disconnection are lost.
The Fix: For most IoT applications, use clean_session=False with a persistent client ID:
# BAD: Clean session loses all state on reconnectclient.connect(broker, clean_session=True)# GOOD: Persistent session retains subscriptions and queued messagesclient.connect(broker, client_id="device-ABC123", clean_session=False)
With persistent sessions:
Subscriptions survive reconnection
QoS 1/2 messages are queued while client is offline
Session expiry interval (MQTT 5.0) controls how long broker retains state
Show code
{const container =document.getElementById('kc-mqtt-qos-3');if (container &&typeof InlineKnowledgeCheck !=='undefined') { container.innerHTML=''; container.appendChild(InlineKnowledgeCheck.create({question:"Your IoT device connects to an MQTT broker and subscribes to 'commands/#' to receive control messages. The device uses clean_session=false and client_id='device-ABC123'. After a brief network outage (30 seconds), the device reconnects. What happens to commands published during the outage?",options: [ {text:"Commands are lost - MQTT doesn't queue messages",correct:false,feedback:"With clean_session=false, the broker DOES queue QoS 1 and QoS 2 messages for offline clients."}, {text:"Commands with QoS 1 or 2 are delivered; QoS 0 commands are lost",correct:true,feedback:"Correct! Persistent sessions enable message queuing, but ONLY for QoS 1 and QoS 2. QoS 0 messages are never queued."}, {text:"All commands are delivered regardless of QoS level",correct:false,feedback:"QoS 0 messages are never queued - they're only delivered to currently connected subscribers."}, {text:"Commands are delivered only if broker has persistence enabled",correct:false,feedback:"Broker persistence affects survival across broker restarts, not client disconnections."} ],difficulty:"hard",topic:"mqtt-session" })); }}
1189.9 Summary
Key QoS decisions:
Scenario
Recommended QoS
High-frequency sensor data
QoS 0
Alerts and notifications
QoS 1
Critical actuator commands
QoS 2
Battery-constrained devices
QoS 0 (prefer)
Financial transactions
QoS 2
Remember:
QoS 2 costs 4x more than QoS 0 in messages and battery
Use persistent sessions (clean_session=false) for reliable delivery
Default to QoS 0 for 95%+ of IoT telemetry
1189.10 Whatβs Next
Now that you understand MQTT Quality of Service:
Next Chapter: MQTT Security - Secure your MQTT deployment with TLS and authentication