In MQTT, messages with QoS 1 or 2 must be delivered at least once (QoS 2 messages must be delivered exactly once). If the client is not connected, the broker must store the message until the client is ready to receive it.

The HiveMQ blog has an interesting point:

But what happens if a client does not come online for a long time? The constraint for storing messages is often the memory limit of the operating system. There is no standard way on what to do in this scenario. It totally depends on the use case. In HiveMQ we will provide a possibility to manipulate queued message and purge them.

Since this seems to be dependent on the broker, how does Mosquitto handle this situation? Does it just crash after running out of memory or are old messages finally purged?

1 Answer 1


Messages are persisted to disk not just held in memory.

Look at the autosave_interval and autosave_on_change options for when the messages get written to disk.


  • Is my understanding correct that the messages are written to disk however the in-memory is not flushed, causing the mosquitto broker to be limited by the memory of the OS rather than the disk storage. It crashes once the memory exceeds. Feb 11, 2022 at 19:46
  • @BhavinJethra iot.stackexchange.com/a/3021/746
    – hardillb
    Feb 13, 2022 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.