MQTT · Study deck

MQTT Production Operations

Picture a building service that accepts thousands of sensor messages during a calm test.

Broker Bex is your guide for this deck.

reviewproduction
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Design Scalable Architectures: Design MQTT broker clustering strategies for high availability and horizontal scaling
  • Configure Security Layers: Configure TLS encryption, certificate-based authentication, and topic-level ACLs for production deployments
  • Diagnose Performance Bottlenecks: Analyze broker metrics to identify and resolve CPU saturation, message throughput limits, and QoS overhead
  • Evaluate QoS Trade-offs: Assess the cost and reliability implications of each QoS level and select the appropriate level for a given data type
iotclass.org

Major section

In 60 Seconds

On release day, one service copy stops, stored work grows, and devices reconnect together.

  • The test message succeeded, but the operating promise was never proved.
  • Telemetry means readings and status sent by a remote device.
  • A protocol is an agreed set of message and timing rules.
  • Message Queuing Telemetry Transport (MQTT) carries named messages through a broker.

Key terms

Latency
Latency means time from sending to a useful result.
Quality of service
Quality of service means rules for different delivery handling.
iotclass.org

Major section

In 60 Seconds (continued)

A broker is the service that receives and routes them.

  • Latency means time from sending to a useful result.
  • Quality of service means rules for different delivery handling.
  • Transport layer security is protection for data moving across a network.
  • Transport Layer Security (TLS) protects a connected path.
iotclass.org

Major section

MQTT Broker Clustering Architecture

The load balancer distributes connections, but correct failover also depends on replicated subscriptions, queued QoS traffic, and retained state; adding nodes alone does not supply those guarantees.

  • That distinction sets up the layer tables and capacity calculation below: size connection handling, fan-out, replication, and durable state as separate parts of the production narrative.
MQTT broker cluster with load balancer, three broker nodes, shared session state, publishers, subscribers, and failover benefits
MQTT broker cluster with load balancer, three broker nodes, shared session state, publishers, subscribers, and failover benefits
iotclass.org

Major section

Security Configuration

This enables TLS with mutual authentication.

  • Production example:: Sensor can publish to sensors/*, read commands addressed to it, cannot access other devices' data.
  • Application-layer encryption only: Misses metadata (topic names visible), doesn't protect credentials.
  • VPN: Adds latency/complexity, not always available on constrained devices.
iotclass.org

Major section

Common Pitfalls

The Mistake: Developers set QoS 2 (exactly-once delivery) for all messages, assuming higher QoS always means better reliability without considering the costs.

  • Real Impact: QoS 2 uses 4x the network messages of QoS 0 and 2x of QoS 1.
  • If delivery matters but the consumer can make duplicate processing safe, QoS 1 supplies retransmission with a simpler exchange.
MQTT QoS selection decision tree matching delivery guarantees to message criticality
MQTT QoS selection decision tree matching delivery guarantees to message criticality
iotclass.org

Major section

Common Pitfalls (continued)

The decision starts with what happens if one publication is lost or repeated, not with the assumption that a larger QoS number is always safer.

  • This ordered choice connects the pitfall's broker and battery cost to a per-message requirement rather than a universal setting.
  • In production with auto-scaling, containerized deployments, or device replacements, multiple instances may attempt to use the same client ID simultaneously.
  • In a real fleet, a firmware update that hardcodes one client ID can turn thousands of healthy devices into a reconnection storm.
iotclass.org

Major section

Protocol Bridging

The gateway forwards normalized events to the cloud broker over MQTT/TCP.

  • CoAP->MQTT: Sensor POST to coap://gateway/sensor/temp -> Gateway publishes to sensors/temp MQTT topic.
  • MQTT->CoAP: Application publishes command to commands/sensor1 -> Gateway converts to CoAP PUT coap://sensor1/config.
  • Sensors use power-efficient CoAP/UDP locally.

Why it matters

Gateway caches sensor data (reduce sensor wake time).

iotclass.org

Major section

Visual Reference Gallery

The aim is to predict fan-out and ACL scope before traffic reaches the broker.

  • An exact filter must match every level; + replaces one level; and a terminal # covers the remaining descendants.
  • This comparison connects hierarchical naming to observable subscriber fan-out, giving production reviews a concrete way to detect over-broad subscriptions and permissions.
MQTT deterministic broker matching with exact, single-level and multi-level subscription filters
MQTT deterministic broker matching with exact, single-level and multi-level subscription filters
iotclass.org

Major section

Worked Example: Sizing an MQTT Broker Cluster for a Smart Building

Scenario: A commercial real estate company is deploying IoT across a 40-floor office tower.

  • Each floor has 80 sensors (temperature, humidity, CO2, occupancy, light) reporting every 30 seconds, plus 20 actuators (HVAC dampers, blinds, lighting zones) receiving commands.
  • The system must achieve 99.9% uptime with sub-200 ms message delivery.
  • But 99.9% uptime requires eliminating single points of failure.

Numbers to remember

99.9%The system must achieve 99.9% uptime with sub-200 ms message delivery.
iotclass.org

Major section

Deep-Dive Note: Production Observability Boundaries

The $SYS tree is the broker's read-only metrics namespace, but it has a wildcard trap: ordinary # and + subscriptions do not match topic names beginning with $.

  • A production MQTT review should prove that failures are visible before users report them.
  • Flow control with Receive Maximum caps unacknowledged QoS 1/2 messages so a slow consumer cannot create unbounded broker memory pressure.
  • Bridging is a security and namespace decision as much as a scaling tool.
iotclass.org

Major section

Reference: MQTT Quick Reference Card

Message Queuing Telemetry Transport (MQTT) means a lightweight way for devices to exchange messages.

  • A protocol means shared rules for that exchange.
  • A broker means the service that passes messages from senders to receivers.
  • A payload means the useful data inside one message.
  • Transmission Control Protocol (TCP) means a stream that checks order and delivery.

Key terms

Telemetry
Telemetry means readings and status sent by a remote device.
Transport layer security
Transport layer security means protection for that stream; it is called TLS.
Quality of service
Quality of service means the delivery promise chosen for a message; it is called QoS.
iotclass.org

Major section

Reference: MQTT Quick Reference Card (continued)

Transport layer security means protection for that stream; it is called TLS.

  • A WebSocket means a lasting two-way link between a browser and a service.
  • Quality of service means the delivery promise chosen for a message; it is called QoS.
  • A broad subscription such as # or +/status does not receive $SYS/. Messages; subscribe with a filter that also starts with $, such as $SYS/#, when broker telemetry is the intended target.
iotclass.org

Deck summary

Key takeaways

On release day, one service copy stops, stored work grows, and devices reconnect together.

  • A broker is the service that receives and routes them.
  • The load balancer distributes connections, but correct failover also depends on replicated subscriptions, queued QoS traffic, and retained state; adding nodes alone does not supply those guarantees.
  • This enables TLS with mutual authentication.
  • The Mistake: Developers set QoS 2 (exactly-once delivery) for all messages, assuming higher QoS always means better reliability without considering the costs.
iotclass.org

Retrieval practice

Recall check 1 of 5

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

Q1Complete the MQTT reconnection with exponential backoff:

Aclient.reconnect()
Bclient.connect()
Cclient.restart()
Dmqtt.reconnect(client)
Show answer

Answer: A client.reconnect() attempts to reconnect using the original connection parameters. Exponential backoff with a cap (min(delay, 60)) prevents overwhelming the broker while limiting maximum wait time.

iotclass.org

Retrieval practice

Recall check 2 of 5

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

Q2A production IoT system connects 5,000 devices using MQTT on port 1883 with username/password authentication. A security audit flags this as a critical risk. Which combination of changes BEST resolves the identified vulnerabilities?

AUse TLS, stronger auth, and topic ACLs.
BKeep port 1883 but add a VPN tunnel, and use strong passwords
CSwitch to port 8883 with TLS only — no ACL changes needed since TLS encrypts everything
DUse application-layer encryption on payloads and keep port 1883
Show answer

Answer: A Correct!

iotclass.org

Retrieval practice

Recall check 3 of 5

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

Q3A smart building deploys 4,000 IoT devices that each publish sensor data every 30 seconds. The team uses QoS 2 for all messages to 'maximise reliability'. Broker CPU reaches 90% at peak. Which analysis BEST explains the root cause and recommends the correct fix?

AThe broker hardware is underpowered; upgrade CPU cores to handle QoS 2 overhead
BQoS 2 is appropriate for sensor data; the real problem is too many subscribers causing fan-out
CDowngrade periodic sensor readings to QoS 0 and reserve QoS 1 for critical safety alerts
DSwitch to a clustered broker to distribute the QoS 2 processing across multiple nodes
Show answer

Answer: C Correct!

iotclass.org

Retrieval practice

Recall check 4 of 5

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

Q4Place each MQTT production responsibility where it lives so you can diagnose whether an incident began in fleet identity, broker routing and session state, or backend processing and observability.

AAuthenticated Device Fleet
BHA Broker Cluster and Session State
CBackend Processing and Observability
Show answer

Answer: A Production MQTT separates fleet identity, broker routing and recoverable state, and backend consumption with observability so an outage can be located and safely rolled back.

iotclass.org

Retrieval practice

Recall check 5 of 5

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

Q5Per this MQTT cheat sheet, which QoS level uses a 4-way handshake to guarantee exactly-once delivery?

AQoS 2
BQoS 0
CQoS 1
DQoS 3
Show answer

Answer: A The cheat sheet lists QoS 0 as at-most-once (fire and forget), QoS 1 as at-least-once (with PUBACK), and QoS 2 as exactly-once (4-way handshake).

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A · client.reconnect() attempts to reconnect using the original connection parameters. Exponential backoff with a cap (min(delay, 60)) prevents overwhelming the broker while limiting maximum wait time.
  2. A · Correct!
  3. C · Correct!
  4. A · Production MQTT separates fleet identity, broker routing and recoverable state, and backend consumption with observability so an outage can be located and safely rolled back.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. A · The cheat sheet lists QoS 0 as at-most-once (fire and forget), QoS 1 as at-least-once (with PUBACK), and QoS 2 as exactly-once (4-way handshake).
iotclass.org