kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

Kafka topic reverse reading

Open vshlapakov opened this issue 11 years ago • 3 comments

Guys, there's an old idea to read topic in reverse: we have several cases where it could ease our life a lot. As far as I see, it could be done by creating another consumer class that will start from latest offsets and decrease it gradually, all other details should stay practically the same. So far, my question is: do you see any limitations of the library/kafka protocol that could stop us from using such approach? In my understanding, there're no implemented optimizations related with reading messages in a normal mode, so correct reverse-read implementation should be also comparatively efficient. Just in a case, here's Jay Kreps's opinion) that makes me think in such way. I don't ask to implement it at once, so it's just a question, thanks in advance for your thoughts.

vshlapakov avatar Jun 15 '15 06:06 vshlapakov

Seems reasonable to me -- there would need to be some "magic" to decide what offset + maxbytes to use for each FetchRequest, since there is no way to precisely fetch X messages starting at Y offset. My only suggestion would be to try to avoid creating a new consumer class and see if we can leverage the existing classes but perhaps w/ a parameter like reverse=True

dpkp avatar Jun 15 '15 15:06 dpkp

Did this idea get implemented? I can see usefulness for when an application publishes heartbeats (for different keys). A consumer (which reads and sinks the last update to a DB for instance) would only care about the last heartbeat for each key. Hence reading backwards would be simpler since the consumer can safely write each key it sees the first time (since that's the latest), and ignore any other datum.

p.s. Kafka's Log Compaction lets you keep the last update per key, but only in the tail of a partition. The head will still contain multiple updates.

whipit avatar Apr 17 '18 20:04 whipit

Closing this for now as we've moved to primarily supporting the Java models. It's not that hard to wrap the consumer to do this yourself if you need it. And if someone really wants to sell us, we might be open to a PR.

jeffwidman avatar Feb 12 '20 20:02 jeffwidman