[ How the consumer ensure the consistency with the producer in Kafka? ]
For example, I have only one broker and one topic named 'Test-topic' with 3 partitions and 2 replicas. When the producer send 3 messages to the topic,
- the 1st message will be stored in partition 1
- the 2nd message will be stored in partition 2
- the 3rd message will be stored in partition 1
when the consumer read the data from this topic, how should it ensure the message order is still 1\2\3 messages?
Answer 1
The only guarantee kafka provides is that, messages will be ordered within a partition. See this link
Messages sent by a producer to a particular topic partition will be appended in the order they are sent. That is, if a message M1 is sent by the same producer as a message M2, and M1 is sent first, then M1 will have a lower offset than M2 and appear earlier in the log.
A consumer instance sees messages in the order they are stored in the log.
In your case, the consumer could see the messages like 1\2\3 OR 1\3\2 OR 2\1\3