# Persistent on both client and server

**URL:** <https://community.hivemq.com/t/persistent-on-both-client-and-server/44>\
**Category:** MQTT\
**Created:** [April 25, 2019, 11:10am UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44 "2019-04-25T11:10:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![caevv](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@caevv](https://community.hivemq.com/u/caevv)\
**Post date:** [April 25, 2019, 11:10am UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44/1 "2019-04-25T11:10:29Z")

</div>

I’m having some issues losing data even with persistent set and clean flag `false`.

When my subscriber lost connection, when it gets back, it doesn’t catchup with data, but start just from the new messages.

I do have persistent storage on my server, but on client it’s just memory. Do I need to have in both client and server in order to guarantee persistent data?

Many thanks.

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [April 25, 2019, 12:01pm UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44/2 "2019-04-25T12:01:24Z")

</div>

Hey Caevv,

can you please describe what you are seeing in a little bit more detail.

- What Broker / Client implementation are you using?
- Which QoS level are the messages being sent in?
- Which MQTT version are you using?
- What is the exact behaviour you are seeing?
- What is the expected behaviour you want to see?

---

<div class="post-metadata">

**Author:** ![caevv](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@caevv](https://community.hivemq.com/u/caevv)\
**Post date:** [April 25, 2019, 12:30pm UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44/3 "2019-04-25T12:30:58Z")

</div>

- What Broker / Client implementation are you using?  
Broker: Mosquitto  
Client: eclipse/paho.mqtt.golang

- Which QoS level are the messages being sent in?  
2

- Which MQTT version are you using?  
Mosquitto

- What is the exact behaviour you are seeing?

1. Subscriber lose connection
2. Messages still being produced
3. Subscriber connects, but start from new messages only.

- What is the expected behaviour you want to see?

1. Subscriber lose connection
2. Messages still being produced
3. Subscriber connects, start reading messages from the point is lost connection, until it catchup and then move to live data.

Many thanks.

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [April 26, 2019, 8:24am UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44/4 "2019-04-26T08:24:19Z")

</div>

Hey there. Thank you for you response.

When using cleanSession=false you should see the behaviour you are expecting  
See [this blogpost](https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages/)  
If you want to quickly verify that your client implementation is correct, you can test against the public HiveMQ broker at tcp://broker.hivemq.com:1883

---

<div class="post-metadata">

**Author:** ![caevv](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@caevv](https://community.hivemq.com/u/caevv)\
**Post date:** [April 26, 2019, 10:01am UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44/5 "2019-04-26T10:01:32Z")

</div>

Thanks.

Yes, I saw that post, my concern was because of this part:

> ### Persistent session on the client side
> 
> Similar to the broker, each MQTT client must also store a persistent session. When a client requests the server to hold session data, the client is responsible for storing the following information:
> 
> - All messages in a QoS 1 or 2 flow, that are not yet confirmed by the broker.
> - All QoS 2 messages received from the broker that are not yet completely acknowledged.

And I use MemoryPersistence on client, which means if client restart, it loses the session. But the broker do have in file persistence. In this case, would the persistency still work?

---

<div class="post-metadata">

**Author:** ![hivemq-support](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/hivemq-support/32/357_2.png) [@hivemq-support](https://community.hivemq.com/u/hivemq-support)\
**Post date:** [May 9, 2019, 10:19am UTC](https://community.hivemq.com/t/persistent-on-both-client-and-server/44/6 "2019-05-09T10:19:18Z")

</div>

@caevv

Please excuse my delayed response.  
HiveMQ will persist a clients session regardless of the clients persistence configuration.  
This means that all subscriptions will be persisted on the broker and messages arrived on topics that match the clients subscriptions will be held in an offline message queue and then delivered to the client upon re-connection.

In case you are looking for specific implementation details regarding the Paho Golang or mosquitto broker implementation, please refer to the corresponding support or community.

Thank you and kind regards,  
Florian from The HiveMQ Team.
