Search code examples
apache-kafkakafka-consumer-api

How can I guarantee message ordering from the consumer side?


Let's say that the producer sends 3 events in a specific order (and the order is very important) for 3 different consumers, all these events are going to the same topic and all the consumers are subscribed to that topic.

Let's assume that all the consumers are down, and they all are going to be up again together.

How can I make sure that these consumers will maintain the order of the events?


Solution

    • If your produces data is not belongs to one partition, Then consuming order can not be guaranteed.
    • So if there is multiple partition for your topic then you need to consider about the partitioner of the producer. If it is hash-based then messages with same key are produced to the same partition and consumer is guaranteed to consume them in order.