Search code examples
google-cloud-pubsub

GCP Pub-sub push subscription with message ordering, expected failure behavior


I have a push subscription set up with message ordering enabled. I also have a dead-letter topic/subscription set up. I published 5 messages with the same ordering key, and message #2 fails.

Message #2 went to the dlq but messages #3-5 were all delivered. I expected them to fail immediately and go to the dlq. Is the expected behavior that messages #3-5 still get delivered even though #2 failed?


Solution

  • Yes, this is expected behavior. If Pub/Sub were to send subsequent messages to the dead letter topic, it would have to send all messages for that ordering key to the dead letter topic for the reset of the life of the subscription, essentially making that key unusable. As stated in the documentation, "order might not be preserved when messages are written to a dead-letter topic." This is a tradeoff one must make if there is the chance that a message may not be able to be processed and a dead letter topic is necessary.

    If you want to have more control over the handling of subsequent messages for a key when one message gets written to the dead letter topic, then you'd need to implement your own logic in the subscriber that marks keys bad and publishes the messages to a dead letter topic.