Delay message processing and delete before processing

Depends on if you write the subscribers as well or not:

You have control over your subscriber's code:

  1. In your PubSub messages add a timestamp for when you want that message to be processed.
  2. In your clients (subscribers), have logic to acknowledge the message only if the timestamp to process the message is reached.
  3. PubSub will retry delivering the message until it's acknowledged (or 10 days)

If you don't have control over your subscriber you can have a my-topic and my-delayed-topic. Folks can publish to the former topic and that topic will have only one subscriber which you will implement:

  1. Publish message as before to my-topic.
  2. You will have a subscriber for that topic that can do the same throttling as shown above.
  3. If the time for that message has reached your handler will publish/relay that message to my-delayed-topic.

You can also implement the logic above with task-queue+pubsub-topic instead of pubsub-topic+pubsub-topic.


Just wanted to share that I noticed Pub/Sub supports retry policies 1 that are GA as of 2020-06-16 2.

If the acknowledgement deadline expires or a subscriber responds with a negative acknowledgement, Pub/Sub can send the message again using exponential backoff.

If the retry policy isn't set, Pub/Sub resends the message as soon as the acknowledgement deadline expires or a subscriber responds with a negative acknowledgement.

If the maximum backoff duration is set, the default minimum backoff duration is 10 seconds. If the minimum backoff duration is set, the default maximum backoff duration is 600 seconds.

The longest backoff duration that you can specify is 600 seconds.