Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Producer Partitioning Strategies: DefaultPartitioner (Murmur2 hash), RoundRobin, sticky partitioning, and custom key partitioners.
senior LevelSystem Design
In Simple Words: How Kafka determines which partition an event lands in:
- Explicit Partition Specified: Message is routed directly to that partition index.
- Key Provided (Default): Kafka calculates
murmur2(key) % total_partitions. Guarantees all events with the same key (e.g.order_12345) land in the exact same partition in strict sequential order. - No Key Provided (Sticky Partitioning in modern Kafka): Batches messages to a single partition until
batch.sizeorlinger.msis reached, then rotates to the next partition. Dramatically reduces request count and improves batch compression.