0
0
Kafkadevops~10 mins

Partition ordering guarantees in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to produce messages to a specific partition in Kafka.

Kafka
producer.send(new ProducerRecord<>("topic", [1], "key", "value"));
Drag options to blanks, or click blank then click option'
A0
Btrue
Cnull
D"partition"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for partition number.
2fill in blank
medium

Complete the code to ensure message ordering within a partition by setting the correct key.

Kafka
producer.send(new ProducerRecord<>("topic", [1], "value"));
Drag options to blanks, or click blank then click option'
Anull
B"timestamp"
C"userID"
D"partitionKey"
Attempts:
3 left
💡 Hint
Common Mistakes
Using null key causes round-robin partitioning, losing ordering guarantees.
3fill in blank
hard

Fix the error in the code to consume messages in order from a single partition.

Kafka
consumer.assign(Collections.singleton(new TopicPartition("topic", [1])));
Drag options to blanks, or click blank then click option'
Anull
B0
C"partition"
D"0"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing partition as a string instead of integer.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps partitions to their last committed offsets.

Kafka
offsets = {tp.partition(): [1] for tp in consumer.assignment() if tp.partition() [2] 0}
Drag options to blanks, or click blank then click option'
Aconsumer.committed(tp)
Bconsumer.position(tp)
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using consumer.position() instead of committed offsets.
Using '==' instead of '>'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps partition numbers to their latest offsets if offset is greater than 100.

Kafka
latest_offsets = { [1]: [2] for tp in consumer.assignment() if [3] > 100}
Drag options to blanks, or click blank then click option'
Atp.partition()
Bconsumer.position(tp)
Dtp.offset()
Attempts:
3 left
💡 Hint
Common Mistakes
Using tp.offset() which is invalid.
Filtering with wrong offset value.