I'm looking for an update on a new feature that ha...
# general
z
I'm looking for an update on a new feature that had been discussed: redelivery on nack where order of messages is guaranteed (i.e. not redelivering failed messages out of order). We have a use case where order of messages is more important than speed of delivery. In conversations with StreamNative close to a year ago, I understood that that capability was actively being planned, but I don't see a Pulsar blog post about it (or anything after October 2024). Can someone provide an update?
d
Is there an associated PIP for this feature request?
z
Great question. I'm going to need to review existing PIPs before I reply...
🙏 1
l
@Zach Blocker Are you specifically looking for support for nack with Key_Shared subscriptions? There's https://github.com/apache/pulsar/issues/23480 about that. I'm planning to work on that.
d
@Zach Blocker, as an alternative, you could use an exclusive subscription and disable the ack timeout. Then, when you pull a message off the topic, you can hold onto it as long as necessary. Then messages won’t get delivered out of order. You will control the message flow entirely from inside your application logc.
z
@Lari Hotari Yes, I believe that is what we were looking for. @David K thanks for your reply. While exclusive is an option, of course, we are switching to Pulsar partly for the ability to scale out our consumers, which means Key_Shared subscription. Right now we have a custom setup that is hard to scale.
d
No problem. I just wanted to provide a potential option in case you were blocked on this issue. 😃
✅ 1
z
@Lari Hotari Are you able to give me a sense of timeframe on the issue - you said you were planning to work on it...
l
@Zach Blocker I have a session "Mastering Key-Ordered Message Processing in Apache Pulsar" next month at Data Streaming Summit SF 2025 where I'd like to be able to talk more about the details and possibly demonstrate it. (in https://datastreaming-summit.org/event/data-streaming-sf-2025/schedule , click "Tuesday", then the session title to see the abstract) The goal would be to get this feature into Pulsar 4.1 or 4.2 . Since it most likely requires protocol changes, it's unlikely that it would be backported to Pulsar 4.0. Besides Key_shared subscription, there might also be other alternative solutions in Pulsar that could be useful for handling your use case. Regarding strict key ordered handling of messages with the AUTO_SPLIT Key_Shared mode has some other gaps besides Nack support for certain use cases. This is the guarantee that Key_Shared
AUTO_SPLIT
mode provides:
For Key_Shared subscriptions, messages with the same key are delivered and allowed to be in unacknowledged state to only one consumer at a time. This ensures that the order of message delivery by key is preserved.
When new consumers join or leave, the consumer handling a message key can change when the default
AUTO_SPLIT
mode is used, but only after all unacknowledged messages for a particular key are acknowledged or the original consumer disconnects.
In some key-ordered message processing use cases, there's a need to detect when a key has been assigned to another consumer. There's a very old issue https://github.com/apache/pulsar/issues/6555 . The solution "send Key hash range change events" alone might not be a sufficient solution to address the use case since there's also a need to know the hashes of individual messages. The hashing algorithm itself is an implementation detail of the broker side and that's why sending the key hash range change events alone isn't considered as a great solution. One possibility would be to pass pre-calculated hashes from the broker with the dispatched messages to the client side so that hashing algorithm could be decoupled between the broker and the client and the client wouldn't need to calculate the hash for each message. I have plans to cover hash range change events during the planning of https://github.com/apache/pulsar/issues/23480 . It's possible that some details could be covered in shared PIP (Pulsar Improvement Proposal) design documents which describe the required Pulsar protocol changes to support these features. Does your use case require detecting when a key has been assigned to another consumer when using Key_Shared subscription's AUTO_SPLIT mode?
d
Hey @Lari Hotari, I work with @Zach Blocker. Q/A • Does your use case require detecting when a key has been assigned to another consumer when using Key_Shared subscription's AUTO_SPLIT mode? ▪︎ Answer: No our Event consumers are currently stateless Questions Back to you: 1. When will 4.1 or 4.2 be officially released publicly? 2. Since the Key is stored as a hash wont this Guarantee cause a collision with other keys? ◦ If that's the case what happens when I nack the older one, even though the keys are different and hashes the same? ◦ Maybe it would be better to store the keys instead of hashes in the engine. Because that also would allow the reader clients to be able to load specific events by key. And that's needed for event sourcing. 3. Will the C#/F# clients be updated to work with this? ◦ These clients seem to always be slow to have updates.
l
> 1. When will 4.1 or 4.2 be officially released publicly? It's hard to give exact dates when the release containing this new feature is available. There has been a decision in the Pulsar project, that releases would happen with a fixed cadence, but we haven't kept up with that. The release policy regarding release frequency is documented in https://pulsar.apache.org/contribute/release-policy/#release-frequency-and-support-expectation . A new feature release could take about 3 to 5 weeks until the release is publicly made available after the implementation of the included features have completed. If this new feature doesn't make it to 4.1, there might be another reason to start the 4.1 release very soon and that would postpone the release of the feature until 4.2 release. One of the reasons why I haven't been pushing to release 4.1 with the original frequency is that there aren't currently features in the master branch that would need to be released, at least there hasn't been feedback from the community about that. My current estimate for 4.1 is between October 15th to November 28th. If nack support for Key_Shared isn't ready to be released by then, it would go into 4.2 which would happen around January 15th, 2026. > Since the Key is stored as a hash wont this Guarantee cause a collision with other keys? > ◦ If that's the case what happens when I nack the older one, even though the keys are different and hashes the same? > ◦ Maybe it would be better to store the keys instead of hashes in the engine. Because that also would allow the reader clients to be able to load specific events by key. And that's needed for event sourcing. That's a good question. In the current design of Key_Shared, key hashes are used to reduce the amount of resources (memory) required for tracking such cases. The initial discussions with @merlimat about nack support for Key_Shared have been that the hash level tracking would be preserved. However, it's possible that key-level support is needed to cover the "draining" of inflight messages and no new messages for a particular hash would be sent out to the consumer until the nacked messages have been resolved. In this case, the nacking would be a client side solution with some support from the broker side so that no new messages would be sent for the particular key so that the client wouldn't get overwhelmed with messages that are being retried on the client side. In your case, what would you expect to do with nacked messages? If the messages are put in a DLQ after retries, that would also break ordering. Preserving order with DLQs is a broader challenge. It has been discussed and covered in the Kafka context in Gunnar Morling's LinkedIn post about a month ago https://www.linkedin.com/posts/gunnar-morling_apachekafka-activity-7341860479910195200-G0c2/ and in the referenced Confluent blog post https://www.confluent.io/blog/error-handling-patterns-in-kafka/#pattern-4 . By now, I have been thinking of limiting scope for nack support of Key_Shared to limit it to retries with back off on the client side and possibly on the broker side. Would that be acceptable in your use case? > Will the C#/F# clients be updated to work with this? > ◦ These clients seem to always be slow to have updates. I believe that it would take more time to have support in these clients. I'm planning to cover the Pulsar Java client.
z
In your case, what would you expect to do with nacked messages?
We were previously experimenting with a smart client approach on our end where we would never nack any messages, but instead utilize a sidecar Pulsar topic to keep track of keys that had a failed message. Any subsequent messages under that key would be queued into the sidecar topic so their order could be preserved there, until the original failures were resolved. But of course then it became very important to track key hash range changes because there might be a need for another consumer to assume responsibility for a key that had messages in the failure handling sidecar topic.
d
Indeed that is an interesting problem with DLQ, basically recreates the original issue of out of order messages. idk if DLQ would be a good idea because of this. I have two possible solutions for you: Option A) Store the state of failed keys somewhere and the first MessageId it failed on, It could be in a topic (Compaction or Table View) or somewhere in bookkeeper. It would need the following Actions: • Create Failed Key (w/ Starting MessageId) • Update Failed Key MessageId with any Acked MessageId calls • Resolve Failed Key -- (would be ideal to remove if possible) On the consumer side you just skip any active failed keys. And then when you want to replay nacked messages, you already have preserved order by the original topic. You just need to use a reader with the list of failed Hashes and a MessageId to call seek method. However, If the read messages don't match the exact failed key, don't pass them to the consumer, just skip them. The downfall to this is that as the topic grows the hash collisions grow as we get more keys, so it can. It would be so much more stable if we could just change reader to support a list of keys. Option B) Instead of Storing Just Keys and one message Id have Failed Keys store a list of failed message Ids, and then just use a reader to Seek to any point. This is likely more scalable. Failed Keys would need the following actions: • Create Failed Key (w/ Starting MessageId) • Add another Nacked MessageId to Failed List • Remove acked MessageId • Resolve Failed Key -- (would be ideal to remove if possible)
z
@mayura312