0
0
Kafkadevops~5 mins

Partition key and routing in Kafka - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a partition key in Kafka?
A partition key is a value used to decide which partition a message will go to within a Kafka topic. It helps organize messages so related data stays together.
Click to reveal answer
beginner
How does Kafka use the partition key for routing messages?
Kafka applies a hash function to the partition key. The result determines the partition number where the message is stored, ensuring messages with the same key go to the same partition.
Click to reveal answer
intermediate
Why is it important to use a partition key in Kafka?
Using a partition key ensures message order for related data and balances load across partitions. Without it, messages might be distributed randomly, losing order and grouping.
Click to reveal answer
intermediate
What happens if a message is sent without a partition key in Kafka?
If no partition key is provided, Kafka distributes messages in a round-robin way across partitions. This can improve load balancing but may lose message order for related data.
Click to reveal answer
advanced
Explain the relationship between partition key and consumer groups in Kafka.
Partition keys determine message placement in partitions. Consumer groups read from partitions independently, so messages with the same key go to the same partition and are processed in order by one consumer.
Click to reveal answer
What does Kafka use to decide the partition for a message?
AMessage size
BRandom number generator
CTimestamp of the message
DHash of the partition key
What happens if you send a Kafka message without a partition key?
AMessage is dropped
BMessage goes to a random partition
CMessage is sent to all partitions
DMessage is sent to partition 0 only
Why use a partition key in Kafka?
ATo ensure message order for related data
BTo encrypt messages
CTo compress messages
DTo increase message size
Which of these is true about Kafka partitions?
AEach partition can be read by multiple consumers in the same group simultaneously
BMessages in a partition are unordered
CMessages with the same partition key go to the same partition
DPartitions are created dynamically by consumers
How does Kafka ensure load balancing when no partition key is used?
ABy round-robin distribution across partitions
BBy sending all messages to one partition
CBy hashing the message content
DBy using the message timestamp
Describe how Kafka uses a partition key to route messages to partitions.
Think about how hashing helps keep related messages together.
You got /4 concepts.
    Explain the impact of not using a partition key when sending messages in Kafka.
    Consider what happens to message order and partition choice.
    You got /4 concepts.