I read most of the documentation available about how GCloud pubsub works and it's still not clear to me what happens when a message fails to be acknowledged by the subscriber? I can see on the subscriber settings you have the option to store unacknowledged messages for up to 7 days for free.1 I assume this should work if after many attempts the delivery is still unsuccessful and the message doesn't arrive where it's supposed to?
If this is the case, what is the point of using dead lettering for this subscription?(which is not free) 2. What if you use dead lettering but don't tick the box to enable message retaining (img 2), does it still retain unacknowledged messages?If yes for how long? Also while the subscription already stores it too?
If a message is not acknowledged, then it remains in the set of unacknowledged messages for a subscription. If there is no dead letter topic set up, then Cloud Pub/Sub attempts to redeliver this message up to the message expiration time, which can be up to seven days as you point out.
You may want to use a dead letter topic for several reasons:
A dead letter topic is not any different from a regular Pub/Sub topic. When it is set as the dead letter topic for a subscription, it just means that the Pub/Sub service itself publishes to this topic on your behalf with the messages that were not acknowledged after being delivered up to the maximum number of delivery attempts. Once published to the dead letter topic, Cloud Pub/Sub acknowledges the message in the original subscription on your behalf, meaning it is no longer an unacknowledged message on that subscription.
Consequently, the the message is independent of the original version of the message and is stored separately. If you do not select enable message retention nor have a subscription set up on the dead letter topic, then the message is not retained. If you do, then the message is stored until the topic retention deadline if using the former or the subscription message retention duration if using the latter.