Library

Volume 1 · IoT Technologies

Notebook
Sign in

Section 49

IoT Architecture & Protocols (MQTT, AMQP, CoAP — comparison)

706 words · about 3 min

49.1 IoT Reference Architecture

┌─────────────────────────────────────────────────────────────┐
│                      IoT System Architecture                 │
│                                                             │
│  DEVICE LAYER        CONNECTIVITY      PLATFORM LAYER       │
│  ┌──────────┐       ┌──────────────┐  ┌─────────────────┐  │
│  │ Sensors  │──────►│ IoT Gateway  │  │  AWS IoT Core   │  │
│  │ Actuators│  Zigbee│ (Edge Device)│  │  (MQTT Broker)  │  │
│  │ Cameras  │  Z-Wave│              │  │                 │  │
│  │ RFID     │  BLE   │ - Protocol   │  │  Rules Engine   │  │
│  │ Meters   │  WiFi  │   translation│  │  Device Shadow  │  │
│  └──────────┘       │ - Local proc │  │  Fleet Indexing │  │
│                     │ - Buffering  │  └────────┬────────┘  │
│                     └──────┬───────┘           │           │
│                            │ MQTT/HTTPS         │           │
│                            ▼                   ▼           │
│                   ┌─────────────────────────────────────┐  │
│                   │        DATA PROCESSING LAYER        │  │
│                   │  Kinesis Data Streams               │  │
│                   │  Lambda (real-time processing)      │  │
│                   │  Kinesis Analytics (SQL on streams) │  │
│                   └──────────────┬──────────────────────┘  │
│                                  ▼                          │
│                   ┌─────────────────────────────────────┐  │
│                   │           STORAGE LAYER              │  │
│                   │  S3 (raw data lake / data archive)  │  │
│                   │  Timestream (time series metrics)   │  │
│                   │  DynamoDB (device state / config)   │  │
│                   │  Redshift (historical analytics)    │  │
│                   └──────────────┬──────────────────────┘  │
│                                  ▼                          │
│                   ┌─────────────────────────────────────┐  │
│                   │        APPLICATION LAYER             │  │
│                   │  QuickSight (dashboards)            │  │
│                   │  Custom APIs (mobile/web apps)      │  │
│                   │  Alerts & Notifications (SNS)       │  │
│                   └─────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘

49.2 Protocol Comparison

Protocol Transport QoS Power Range Best For
MQTT TCP 0,1,2 Low Network General IoT, telemetry
AMQP TCP High Medium Network Enterprise messaging, queuing
CoAP UDP 0,1 Very Low Network Constrained devices, HTTP-like
HTTP/REST TCP None High Network Request-response, APIs
WebSocket TCP High High Network Bi-directional, real-time
MQTT-SN UDP 0,1,2 Very Low Network Very constrained devices

Short-range:

Protocol Range Speed Power Use Case
Bluetooth LE 10–100m 1–2 Mbps Very Low Wearables, beacons, health
Zigbee 10–100m 250 Kbps Very Low Smart home, sensors, mesh
Z-Wave ~30m 100 Kbps Very Low Smart home, lighting
WiFi ~50m High High Cameras, appliances
NFC <10cm 100–400 Kbps Passive Asset tagging, payments
RFID 0.1–10m Low Passive Inventory, access control

LPWAN (long range, low power):

Protocol Range Speed Battery Use Case
LoRaWAN 2–15km 0.3–50 Kbps 10+ years Smart agriculture, smart city
NB-IoT Wide (cellular) 200 Kbps 10+ years Utilities, smart meters
LTE-M Wide (cellular) 1 Mbps 10 years Asset tracking, wearables
Sigfox 10–50km 100 bps 10+ years Very low-frequency telemetry

49.3 MQTT Deep Dive

MQTT Fundamentals:
  - Publish/Subscribe model
  - Broker-based (AWS IoT Core, Mosquitto)
  - QoS levels:
    0 = At most once (fire and forget)
    1 = At least once (guaranteed delivery, possible duplicates)
    2 = Exactly once (guaranteed, no duplicates — expensive)

Topic structure (hierarchical):
  factory/plant1/line3/machine007/temperature
  home/living-room/thermostat/setpoint

Wildcards:
  + = single level: factory/+/line3/+/temperature
  # = multi level: factory/plant1/#

MQTT Features:
  - Retain flag: Broker saves last message, delivers to new subscribers
  - Last Will & Testament (LWT): Message sent when client disconnects unexpectedly
  - Persistent sessions: Broker queues messages for offline clients

49.4 Q&A

Q1: What is the difference between MQTT QoS 1 and QoS 2? When would you use each?

  • QoS 1 (At-least-once): message delivered at least once; if the ack (PUBACK) is lost the sender retries, causing possible duplicates. Use for telemetry where duplicates are harmless (e.g., a repeated temperature reading).
  • QoS 2 (Exactly-once): four-part handshake (PUBLISH → PUBREC → PUBREL → PUBCOMP), guaranteed no duplicates but higher overhead. Use for commands to actuators (a duplicate “open valve” could be dangerous) or billing/transaction messages. In practice, use QoS 1 for the bulk of telemetry (much more efficient) and QoS 2 only for command/control where duplicate execution has real consequences — at scale, QoS 2’s handshake across thousands of devices creates significant broker load.

Q2: MQTT vs. AMQP vs. CoAP — how do you choose for a new deployment? MQTT for general sensor telemetry over TCP with a lightweight pub/sub model and broad IoT platform support (AWS IoT Core, Azure IoT Hub both broker MQTT natively). AMQP when you need enterprise messaging guarantees — transactions, complex routing, queuing semantics — closer to a message broker than a lightweight telemetry protocol. CoAP for severely constrained devices (battery, memory) needing a RESTful, UDP-based protocol with lower overhead than HTTP.