Middle+
How are topics and partitions related in Kafka? Is message order guaranteed across different partitions?
sobes.tech AI
Answer from AI
In Kafka, a topic is a logical category or stream of messages, divided into multiple partitions for scalability and parallel processing.
Partitions are physical segments of a topic, each storing an ordered set of messages. Messages within a single partition have a strict order and are indexed by offset.
Relationships:
- A topic consists of one or more partitions.
- Producers send messages to specific partitions (by key or round-robin).
- Consumers read messages from partitions.
Order guarantees:
- Message order is guaranteed only within a single partition.
- Order between different partitions is not guaranteed, as they are processed in parallel.
Therefore, if message order is important, it is necessary to ensure that related messages go to the same partition (for example, using the same key).