What Is the MQTT Message Expiry Interval?
The message expiry interval is an MQTT 5 property that puts a shelf life on a message the broker is holding for an offline subscriber. For SCADA, where a two-minute-old flow rate can be worse than no value at all, it is the feature that stops a reconnecting client from being flooded with stale readings. This page explains what the property does, how the broker decrements it, and where it earns its place in a telemetry design.
MQTT Message Expiry Interval in one line: The MQTT message expiry interval is a per-publish property, new in MQTT 5, that tells the broker how many seconds a message may sit in a subscriber's queue before it is discarded undelivered. When a QoS 1 or 2 message is queued for an offline client, the broker counts the interval down; if the client has not reconnected by the time it reaches zero, the message is dropped rather than delivered stale.
What the Property Controls
Message expiry is set by the publisher on an individual PUBLISH packet as one of the MQTT 5 properties. It only matters when a message cannot be delivered immediately, which in practice means it has been queued for a subscriber whose session is still alive but whose network connection is currently down. For a message that is delivered right away the interval is irrelevant. It is a rule about how long a stored, undelivered message stays worth delivering.
The broker treats the interval as a countdown. It records how long the message has been waiting and, when the subscriber finally reconnects, forwards the message with the expiry interval reduced by the elapsed time. If that elapsed time exceeds the original interval, the broker discards the message and the subscriber never sees it. This is fundamentally different from the fire-and-forget of QoS 0; expiry only interacts with the queued messages that persistent sessions and QoS 1 or 2 create.
It is important not to confuse message expiry with session expiry or with retained messages. Session expiry governs how long the broker keeps a client's whole subscription and queue after it disconnects. A retained message is the last-known value the broker hands a brand-new subscriber. Message expiry is narrower than either: it is the lifetime of one specific queued publish. All three can be in play at once for the same client.
Why Stale Telemetry Is a Problem Worth Solving
Consider a gateway that publishes a tank level every few seconds at QoS 1, and a cloud consumer that briefly loses its connection. With a persistent session and no expiry, the broker faithfully queues every level reading during the outage and delivers the entire backlog the instant the consumer reconnects. The consumer now receives a burst of readings that are minutes old, in order, and if it naively writes them to a historian it records a stale value as if it were current, or it thrashes through a backlog before catching up to reality.
Setting a modest message expiry interval on those telemetry publishes changes the behavior to something a control system actually wants. During a short outage only the readings younger than the interval survive; anything older is dropped by the broker. The consumer reconnects and receives just the recent history, or in the extreme case only values still fresh enough to matter. For a live process value, delivering the current reading and discarding the stale backlog is almost always the correct trade, and it keeps the ingestion path from doing pointless work, a concern shared with MQTT to time-series database ingestion.
The judgement is per data type. Live process values want a short expiry so nobody acts on old data. Certain event or command messages want no expiry at all, because a missed setpoint change or a missed alarm acknowledgement is not something you want silently dropped just because the recipient was offline for a while. Deciding the expiry per topic, rather than applying one blanket value, is what separates a thoughtful design from a copied default.
Frequently Asked Questions
Is message expiry available in MQTT 3.1.1?
No. The message expiry interval is one of the MQTT 5 properties and has no equivalent in 3.1.1. Under 3.1.1 a broker holding queued QoS 1 or 2 messages for a persistent session delivers all of them on reconnect with no notion of age, which is exactly the stale-backlog problem that message expiry was introduced to solve. If stale-telemetry handling matters to your design, it is one of the concrete reasons to run MQTT 5 end to end.
Does message expiry apply to retained messages?
Yes, and it is worth knowing. If a publisher sets both the retain flag and a message expiry interval, the broker holds the retained value only until the interval elapses, then removes it. This lets a last-known value expire on its own rather than lingering forever after a node has gone away. Without expiry a retained message persists on the topic until it is explicitly overwritten or cleared, which can leave a very old value being handed to new subscribers.
Sources and verification
This page references the protocol specifications published by the organizations below. Editions, product capabilities, and documentation change over time - confirm current requirements and specifications directly with the source.
- MQTT Version 5.0 (OASIS Standard) - OASIS (v5.0, 2019)
Merobix is not affiliated with, endorsed by, or sponsored by these organizations; their names are used only to identify the standards and products discussed.
Automation services
Need help turning this into a working system?
Merobix integrates SCADA, programs Allen-Bradley and Siemens PLCs, and designs and fabricates industrial control panels.
Meeting requests are reviewed before confirmation.