google-cloud-platformgoogle-cloud-pubsubpublish-subscribesequentialscalable

How ordering is maintained for multiple instance of the same same subscription in GCP Pub Sub


What happens when you have an ordered topic and a scalable subscriber.

I understand that for the ordered topic the ordering (with order key) will be maintained for that subscription. Can we have multiple instance of the same subscription , if yes, then how the ordering will be handled for multiple instance of the same subscription.


Solution

  • The article that accompanied the launch of ordering keys enumerates the ordering properties:

    1. Order: When a subscription has message ordering enabled, subscribers receive messages published in the same region with the same ordering key in the order in which they were received by the service.

    2. Consistent redelivery: If a message is redelivered, then all messages received after that message for the same ordering key will also be redelivered, whether or not they were already acknowledged.

    3. Affinity: If there are messages with an ordering key outstanding to a streaming pull subscriber, then additional messages that are delivered are sent to that same subscriber. If no messages are currently outstanding for an ordering key, the service delivers messages to the last subscriber to receive messages for that key on a best-effort basis.

    If there are multiple subscribers, only a single subscriber will handle messages for a key at a time and messages for that key will be delivered to the subscriber the system has chosen in order. As subscribers come up and go down, keys are reassigned to different available subscribers. Note that redeliveries could shift to a different subscriber if the original delivery's ack deadline expires.