Skip to content

MQTT QoS 1 Messages Duplicated

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about MQTT QoS 1 Messages Duplicated. We cover key concepts, practical examples, and best practices.

The Problem

QoS 1 messages are delivered more than once to the subscriber.

Quick Fix

Wrong

client.publish('cmd', payload, { qos: 1 })  # At least once
Subscriber receives the same message 2+ times.
// Add deduplication in subscriber
const processedIds = new Set()

client.on('message', (topic, payload, packet) => {
  // MQTT 5.0 topic alias or message expiry
  // Use message ID for dedup (QoS 1 has Packet ID)
  if (packet.qos === 1) {
    const msgId = packet.messageId || packet.properties?.messageExpiryInterval
    
    if (processedIds.has(msgId)) {
      return  // Skip duplicate
    }
    processedIds.add(msgId)
  }
  
  console.log('Processing:', topic, payload.toString())
})

// Or use QoS 2 for exactly-once delivery
client.publish('cmd', payload, { qos: 2 })
Messages delivered once (deduplicated or QoS 2).

Prevention

QoS 1 = at least once. Broker stores the message and retries until PUBACK received. The subscriber may get duplicates if PUBACK is lost. Solutions: implement deduplication, use idempotent handlers, or use QoS 2 for exactly-once delivery. QoS 1 message IDs are stored in session for offline queuing.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### Why does QoS 1 duplicate?

If PUBACK from subscriber is lost, the broker retransmits. The subscriber gets the same message again because the broker doesn't know it was received.

Can the subscriber detect duplicates?

QoS 1 packets have a DUP flag (duplicate) and Packet ID. Check the DUP flag to detect retransmitted messages.

Is QoS 1 safe for command messages?

Yes, if the command is idempotent (same command multiple times has no side effects). For non-idempotent commands, use QoS 2.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro