Kafka medium
A Topic has 3 partitions. A Producer sends messages A, B, and C with no specified key. The consumer receives them in the sequence A, C, B. Why is this expected behavior?
- A The consumer's deserializer is likely improperly shifting bits during network transit.
- B Total Ordering: Kafka only guarantees message order *within a single partition*. If messages are distributed across multiple partitions (e.g., via the default Sticky Partitioner), there is no cross-partition global ordering guarantee.
- C The Producer has `retries` enabled, and message B failed its first attempt while C succeeded.
- D Kafka is strictly LIFO (Last-In-First-Out) when multiple brokers are present.
Answer: B. Total Ordering: Kafka only guarantees message order *within a single partition*. If messages are distributed across multiple partitions (e.g., via the default Sticky Partitioner), there is no cross-partition global ordering guarantee.
If you need absolute global ordering, you must use a topic with exactly 1 partition. For most high-scale systems, you use 'Keys' to ensure that related events (e.g., all events for User 1) always land in the same partition, preserving their specific order without sacrificing cluster throughput.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- When implementing 'Exactly-Once Semantics' (EOS) in a Kafka stream, what is the role of the `isolation.level=read_committed` setting on the Consumer?
- Historically, which external service was required by Kafka to manage cluster hierarchy, metadata, and leader election status?
- Once a message is successfully appended to a Kafka partition log, what is its mutability status?
- In a Kafka cluster, what is the role of a 'Broker'?
- What is the primary indicator of a bottleneck in a Kafka consumer's processing logic?
- What is the primary architectural role of Apache Kafka in a distributed system?