MQTT Fundamentals

40 MQTT Interview Questions and Answers for IoT Developers

Forty MQTT interview questions with concise answers covering fundamentals, QoS, sessions, retained messages, Last Will, MQTT 5 and security, plus ways to practice each concept on broker.connectmq.com.

Illustration for MQTT interview questions showing a candidate at a whiteboard sketching a broker, topics and QoS levels
Run this on your own MQTT brokerGet a private, managed MQTT broker on the Free plan and start from ready-made code samples.
Try it free Code samples No card required

These 40 MQTT interview questions cover what hiring managers for IoT, embedded and backend roles actually ask: fundamentals, QoS, sessions, retained messages, Last Will, MQTT 5 and security. Each answer is short enough to say out loud, and the practice section shows how to prove every concept on a live broker before your interview.

How to Use These MQTT Interview Questions

Read an answer, then try to explain it without looking. Interviewers care less about memorized definitions than about trade-offs: when would you use QoS 0, why might retained messages surprise you, what breaks if two devices share a client ID. Where possible, run the commands in the practice section against the free public MQTT broker so you can describe what you saw, not what you read.

Fundamentals (Questions 1 to 10)

1. What is MQTT?

A lightweight publish/subscribe messaging protocol that runs over TCP, designed for constrained devices and unreliable networks. Versions 3.1.1 and 5.0 are OASIS standards.

2. What is a broker?

The server that receives all published messages and routes them to clients with matching subscriptions. It also manages sessions, retained messages and Wills. See what an MQTT broker does.

3. How does publish/subscribe differ from request/response?

Publishers and subscribers never address each other; the broker decouples them in space, time and synchronization. Our article on the publish/subscribe model explains all three.

4. Does MQTT use TCP or UDP?

TCP, optionally wrapped in TLS or WebSocket. MQTT-SN is the variant for UDP and datagram networks.

5. What are the standard ports?

1883 for plain TCP and 8883 for TLS. WebSocket ports are broker-specific; 8083 and 8084 with path /mqtt are common.

6. What is a topic?

A UTF-8 string with levels separated by /, such as site1/line2/temp. Topics are created implicitly when published to.

7. Explain the + and # wildcards.

+ matches exactly one level; # matches all remaining levels and must be the last character of a filter. Wildcards are only valid in subscriptions.

8. What is the client ID used for?

It identifies the session on the broker. Two connections with the same ID cause the broker to disconnect the older one, often producing a reconnect loop.

9. What is keep-alive?

The maximum silence in seconds a client promises. It sends PINGREQ when idle; the broker drops the connection after roughly 1.5 times the interval without traffic.

Small packet overhead, push delivery, outbound-only connections that work through NAT, and built-in reliability features like QoS and persistent sessions.

QoS and Delivery (Questions 11 to 18)

11. Describe the three QoS levels.

QoS 0 is at most once with no acknowledgement. QoS 1 is at least once with PUBACK. QoS 2 is exactly once using PUBREC, PUBREL and PUBCOMP.

12. Is QoS end to end?

No. QoS applies separately to publisher-to-broker and broker-to-subscriber legs. The subscriber receives at the lower of the published QoS and its subscription QoS.

13. When would you choose QoS 0?

For frequent telemetry where the next sample supersedes the last, and where an occasional loss is acceptable.

14. Why can QoS 1 produce duplicates?

If the PUBACK is lost, the sender retransmits with the DUP flag set. Applications must be idempotent or deduplicate.

15. What does QoS 2 cost?

Four packets per message and extra state on both sides, which reduces throughput. Use it only when duplicates are genuinely harmful. More in MQTT QoS levels explained.

16. Does MQTT guarantee ordering?

Messages from one publisher on one topic at the same QoS arrive in order. There is no ordering guarantee across topics or publishers.

17. What is an inflight window?

The number of unacknowledged QoS 1/2 messages allowed at once. MQTT 5 exposes it as Receive Maximum.

18. What happens if nobody subscribes to a topic?

The broker discards the message, unless it is retained.

Sessions, Retained Messages and Last Will (Questions 19 to 27)

19. What is a persistent session?

Broker-side state for a client ID (subscriptions and queued QoS 1/2 messages) kept across disconnects.

20. Clean Session vs. Clean Start?

In 3.1.1, Clean Session controls both reuse and lifetime of the session. MQTT 5 splits this into Clean Start (reuse on connect) and Session Expiry Interval (lifetime).

21. What is a retained message?

The last message on a topic flagged retain, stored by the broker and delivered immediately to new subscribers.

22. How do you delete a retained message?

Publish an empty payload with the retain flag to the same topic.

23. What is a common retained-message pitfall?

Stale state: a device that died long ago still appears "on" because its last retained status was never cleared. Combine with a Last Will.

24. What is Last Will and Testament?

A message registered at connect time that the broker publishes if the client disconnects without a proper DISCONNECT, for example after a network failure.

25. How do you build reliable online/offline status?

Publish a retained "online" after connecting and register a retained Will of "offline" on the same topic.

26. What is Will Delay Interval?

An MQTT 5 setting that postpones the Will so a quickly reconnecting client does not trigger a false offline alert.

27. How long are offline messages kept?

As long as the session lives and broker quotas allow. In MQTT 5, Session Expiry and Message Expiry put explicit limits on it.

MQTT 5 (Questions 28 to 34)

28. Name key MQTT 5 additions.

Reason codes, user properties, session and message expiry, topic aliases, shared subscriptions, request/response properties and enhanced authentication. Overview in MQTT 5 features.

29. What are reason codes?

One-byte codes in acknowledgements and DISCONNECT explaining results, for example 0x87 Not authorized or 0x97 Quota exceeded.

30. What is a shared subscription?

A filter of the form $share/group/topic that distributes messages across group members for load balancing.

31. What is a topic alias?

An integer that substitutes for a long topic name within one connection, reducing bytes per PUBLISH.

32. How does MQTT 5 support request/response?

The requester sets a Response Topic and Correlation Data; the responder publishes its reply to that topic with the same correlation data.

33. What are user properties?

Arbitrary key/value string pairs attached to packets, similar to HTTP headers, useful for metadata like content version or trace IDs.

34. What is Message Expiry Interval?

A per-message lifetime after which the broker drops it if undelivered, preventing stale commands from executing later.

Security and Operations (Questions 35 to 40)

35. How do you secure MQTT?

TLS on 8883, unique credentials per device, least-privilege topic permissions where the broker supports them, and no sensitive data on public brokers. See MQTT security best practices.

36. What is mutual TLS?

TLS where the client presents its own certificate so the broker can authenticate it cryptographically.

37. Why not use port 1883 in production?

Credentials and payloads travel unencrypted and can be captured on any network hop.

38. What are $SYS topics?

Broker-reserved topics exposing status information. Wildcard # subscriptions do not match topics beginning with $.

39. How do you scale MQTT consumers?

Use shared subscriptions to spread load, keep callbacks fast, and scope wildcard subscriptions narrowly.

40. Self-hosted or managed broker?

Self-hosting gives full control but adds patching, certificates, monitoring and scaling work. A managed MQTT broker moves that operational load to the provider.

Practice Before the Interview

Nothing beats having done it. Install mosquitto_pub and mosquitto_sub, choose a random suffix, and run these against broker.connectmq.com (anonymous, unique client ID, public data):

# Q21-22: retained message, then delete it
mosquitto_pub -h broker.connectmq.com -p 1883 -i iq-pub-5c9d \
  -t "connectmq/demo/5c9d/lamp" -m "on" -r -q 1
mosquitto_sub -h broker.connectmq.com -p 1883 -i iq-sub-5c9d \
  -t "connectmq/demo/5c9d/#" -v -C 1
mosquitto_pub -h broker.connectmq.com -p 1883 -i iq-pub-5c9d \
  -t "connectmq/demo/5c9d/lamp" -r -n

# Q24-25: Last Will. Start this, then kill the terminal (not Ctrl+C)
mosquitto_sub -h broker.connectmq.com -p 1883 -i iq-will-5c9d \
  -t "connectmq/demo/5c9d/ping" -k 10 \
  --will-topic "connectmq/demo/5c9d/status" --will-payload "offline" \
  --will-retain --will-qos 1

# Q30: shared subscription (MQTT 5). Run in two terminals with different -i
mosquitto_sub -h broker.connectmq.com -p 1883 -V mqttv5 -i iq-w1-5c9d \
  -t '$share/workers/connectmq/demo/5c9d/jobs' -v

A practice checklist to work through:

  1. Publish at QoS 0, 1 and 2 and watch the packet flow with -d (debug output).
  2. Create a retained message, subscribe, then clear it.
  3. Trigger a Last Will by killing a client abruptly.
  4. Reuse one client ID in two terminals and observe the disconnect loop.
  5. Try a shared subscription with two workers and count which one receives each message.

Review the MQTT tutorial for anything that still feels fuzzy.

Practice on Your Own ConnectMQ Broker

Interviewers love candidates who have run a real deployment. Sign up at app.connectmq.com for a free Serverless broker (no credit card), connect over TLS with the generated credentials, and use ConnectMQ's in-browser client and live topic explorer to show exactly how sessions, retained messages and Wills behave. ConnectMQ supports MQTT 3.1.1 and 5.0, so you can demonstrate both versions.

Frequently Asked Questions

Which MQTT topics come up most in interviews?

QoS levels, persistent sessions, retained messages, Last Will and topic design are near-universal. MQTT 5 features and security are common for senior roles.

Do I need to know MQTT 5 for an interview?

For new IoT projects, yes at least the basics: reason codes, session expiry, shared subscriptions and user properties.

How should I prepare for a practical MQTT task?

Be comfortable with one client library (Python paho-mqtt or MQTT.js) and the Mosquitto CLI tools, and be able to connect over TLS with credentials.

What is a good follow-up question to ask the interviewer?

Ask which broker and MQTT version they run, how they handle device identity, and how they monitor connection state. It shows operational awareness.

Related articles

Why Your MQTT Client Keeps Disconnecting (and How to Fix It)

Reconnect loops are one of the most common MQTT problems. Learn the five usual causes, from duplicate client IDs to keep alive timeouts and oversized packets, and follow a diagnosis flow that pinpoints yours.

8 min read

Who Invented MQTT? The History from Oil Pipelines to IoT

MQTT was invented in 1999 by Andy Stanford-Clark of IBM and Arlen Nipper of Arcom to monitor oil pipelines over satellite. Follow its path to open source, OASIS, ISO and today's managed cloud brokers.

7 min read

MQTT Maximum Message Size: Limits and Large Payload Strategies

MQTT can technically carry a 256 MB packet, but brokers, client libraries and devices impose far lower limits. Learn where the real limits are, what happens when you exceed them, and how to send large payloads.

7 min read

All articles →

Your private MQTT broker is a few clicks away

Create an account, get your broker credentials and connect your first device — no servers to install, patch or scale.