No, in Pulsar's Key_Shared subscription with partitioned topics, there is no guarantee that a particular key will always be routed to the same partition. The assignment of a key to a partition is determined by the producer's routing logic, which typically hashes the key and maps it to a partition, but this is not a strict guarantee at the broker level. The hash range check and key-to-partition mapping are performed on the producer side, not the broker, using the configured routing mode and hashing scheme. The broker only guarantees that, within a partition, all messages with the same key are delivered to the same consumer in order, but does not enforce key-to-partition affinity across the entire topic.
According to
Pulsar documentation and
Message RoutingMode, the producer hashes the key and selects a partition, but this mapping can change if the number of partitions changes or if the producer's routing configuration changes. The broker does not perform a hash range check before accepting the message; it simply receives messages on the partition as determined by the producer. Would you like more detail on how the producer's routing logic works?
Sources:
-
Pulsar: Partitioned Topics
-
Pulsar: Message RoutingMode (Java) 👍 1 button 👎 0 button 💡
Hint: Mention
@RunLLM in the thread for followups.