Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud PubSub Message Delivered More than Once before reaching deadline acknowledgement time

Background: We configured cloud pubsub topic to interact within multiple app engine services, There we have configured push based subscribers. We have configured its acknowledgement deadline to 600 seconds

Issue: We have observed pubsub has pushed same message twice (more than twice from some other topics) to its subscribers, Looking at the log I can see this message push happened with the gap of just 1 Second, Ideally as we have configured ackDeadline to 600 seconds, pubsub should re-attempt message delivery only after 600 seconds.

Need following answers:

  1. Why same message has got delivered more than once in 1 second only

  2. Does pubsub doesn’t honors ackDeadline configuration before reattempting message delivery?

References: - https://cloud.google.com/pubsub/docs/subscriber

like image 971
Paresh Behede Avatar asked Nov 29 '18 11:11

Paresh Behede


People also ask

What is Acknowledgement deadline PubSub?

A predetermined amount of time (this defaults to 10 seconds) is allocated for the client to acknowledge (ack) this message before the server redelivers it. This is known as the acknowledgement deadline.

Does PubSub guarantee delivery?

By default, Pub/Sub offers at-least-once delivery with no ordering guarantees on all subscription types. Alternatively, if messages have the same ordering key and are in the same region, you can enable message ordering.

Is PubSub real time?

Publish-subscribe systems are well suited for distributed real-time system in num- ber of ways [2,3]. First, events are delivered to the subscribers immediately after event occurrence, thus subscriber can access the event data in real-time. Second, it is asynchronous.

Can PubSub hold millions of messages?

There is no limit on the number of retained messages. If subscribers don't use a subscription, the subscription expires.


1 Answers

Message redelivery can happen for a couple of reasons. First of all, it is possible that a message got published twice. Sometimes the publisher will get back an error like a deadline exceeded, meaning the publish took longer than anticipated. The message may or may not have actually been published in this situation. Often, the correct action is for the publisher to retry the publish and in fact that is what the Google-provided client libraries do by default. Consequently, there may be two copies of the message that were successfully published, even though the client only got confirmation for one of them.

Secondly, Google Cloud Pub/Sub guarantees at-least-once delivery. This means that occasionally, messages can be redelivered, even if the ackDeadline has not yet passed or an ack was sent back to the service. Acknowledgements are best effort and most of the time, they are successfully processed by the service. However, due to network glitches, server restarts, and other regular occurrences of that nature, sometimes the acknowledgements sent by the subscriber will not be processed, resulting in message redelivery.

A subscriber should be designed to be resilient to these occasional redeliveries, generally by ensuring that operations are idempotent, i.e., that the results of processing the message multiple times are the same, or by tracking and catching duplicates. Alternatively, one can use Cloud Dataflow as a subscriber to remove duplicates.

like image 99
Kamal Aboul-Hosn Avatar answered Sep 19 '22 12:09

Kamal Aboul-Hosn