I have a subscription with ordering enabled and I am setting an ordering key when enqueuing messages on a topic. In practice I see very little evidence of subscriber affinity in the logs. This does not technically violate the specification as subscriber affinity on an ordering key is best effort, but not guaranteed.
What I do however need to guarantee is strict ordering, to avoid lock contention in my database when persisting data read from an ordered subscription. There is a one-to-one correlation between ordering keys and database locks. For a given ordering key I do not want to read the next message until the previous one has been explicitly acknowledged, regardless of which subscriber consumes the next message. This way despite having an ordered subscription shared by many subscribers, and messages with the same ordering key consumed by different subscribers, I will still avoid lock contention in the database, which is currently a very real problem in production.
(I should note that in my case I cannot use message attributes for this, because pubsub does not allow dynamic filtering, and the number of nodes with subscribers is dynamically autoscaled and not deterministic. Therefore mapping a message attribute to a subscriber via modulo division is not an option)
I know that I am not the first person to use ordering keys for this purpose: Subscriber affinity with Ordering Key, but without *in-order* delivery
In practice I found subscriber affinity to be rather loose. I can live with this as long as I know that for a given ordering key a new message will not be read, until the previous message has been acknowledged, regardless of which subscriber reads the next message. Is this guaranteed by pubsub???
If "message1" and "message2" are enqueued in that order and have the same ordering key, on an ordered subscription, "message2" cannot be read until "message1" has been read, but can be "message2" be read before "message1" has been acknowledged???