The broker can remember subscriptions, queued QoS 1/2 messages, and in-flight QoS handshake state for a returning client.
MQTT Session Management Workbench
Trace how MQTT brokers keep or discard client session state across disconnects.
MQTT Session Management Workbench
A connection is temporary, but a session can outlive that connection. Use this workbench to see when the broker keeps subscriptions and offline messages, when it returns Session Present, and why stable ClientIDs matter for sleepy or unreliable IoT devices.
A persistent session lets a sensor sleep, reconnect with the same identity, and receive missed reliable messages.
Watch the subscription stay on the broker, messages enter the queue, and Session Present become true on reconnect.
Clean Start controls whether a connect resumes old state. Session Expiry controls how long state survives after disconnect.
Run a reconnect case
Use the scenarios for common IoT patterns, then adjust one setting at a time.
Reconnect identity and lifetime
Messages published while the client sleeps
Broker session shelf
Step through the flow to see where the broker keeps state and where messages are lost.
IoT client
Broker session state
Command publisher
Session resumes and queued commands drain
The same ClientID reconnects without starting clean before the session expires, so the broker returns Session Present = 1 and delivers the stored QoS 1/2 messages.
Reconnect resumes stored state.
Subscriptions are session state, not retained messages.
QoS 1/2 messages can wait for the client.
Delivered when the session resumes.
No loss in this configuration.
In MQTT 5, Clean Start = 1 tells the broker to start a new session. Clean Start = 0 asks the broker to reuse an existing session if one is still present.
In MQTT 5, Session Expiry controls how long state survives after disconnect. An interval of 0 deletes the session when the network connection closes.
MQTT 3.1.1 combines the teaching idea into Clean Session: true starts fresh and discards state; false keeps a persistent session.
Session state is keyed by ClientID. A rebooting device that generates a new ClientID cannot resume the old subscription or offline queue.
Subscriptions, queued QoS 1/2 messages for matching subscriptions, and in-flight QoS state can be part of the server-side session.
Sessions do not create history for topics without subscriptions, do not replace retained messages, and do not prove that an actuator completed an action.
MQTT 5 allows a server to store QoS 0 pending messages, but clients should not rely on that optional behavior. This workbench treats reliable offline delivery as QoS 1/2.
Real brokers impose queue limits, expiry rules, persistence storage limits, and administrative cleanup. Design for those limits explicitly.
Technical notes and primary sources
This model follows the MQTT distinction between connection lifetime, session state, Clean Start or Clean Session, ClientID, QoS, and expiry. It intentionally separates retained messages from session queues: a retained message is broker topic state; a queued offline message belongs to a client session.
- Use Session Present as a diagnostic signal: true means the broker is resuming a previous session for that ClientID.
- Use stable ClientIDs for devices that need offline delivery. Random ClientIDs are appropriate only for clients that do not need session continuity.
- Use QoS 1 or QoS 2 for messages that should survive a subscriber disconnect, then check broker limits and message expiry.
Practice prompts for independent learners
Set MQTT 5, resume, same ClientID, 5 minute session expiry, and 20 minute offline duration. Before stepping, predict Session Present and delivery.
Switch only the publish QoS from 1 to 0. Explain why the broker cannot be relied on to drain those messages later.
Use the Wrong ClientID preset. Decide whether the old broker session is gone or simply unreachable by the new client identity.
For a battery sensor that wakes every hour, choose a session expiry, message expiry, and QoS level that avoids stale commands.