Senior
Is it possible to read messages in the same order they were written from a topic distributed across three partitions?
sobes.tech AI
Answer from AI
In Kafka, if a topic is distributed across multiple partitions, it is not possible to guarantee a global order of messages across the entire topic. The order of messages is preserved within each partition, but the order between partitions is not defined.
If you need to read messages in the same order they were written, then:
- You should read from a single partition.
- Or use message keys so that they go to the same partition and maintain order.
Example: if a topic has 3 partitions, messages with different keys will be distributed across different partitions, and the order between them is not guaranteed.