0
0
Kafkadevops~20 mins

Error handling in clients in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Error Handling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output when a Kafka consumer encounters a deserialization error?
Consider a Kafka consumer configured with a custom deserializer that throws an exception on invalid data. What will the consumer do when it reads a corrupted message?
Kafka
try {
  ConsumerRecord<String, String> record = consumer.poll(Duration.ofMillis(100)).iterator().next();
  String value = record.value(); // Custom deserializer may throw here
  System.out.println("Received: " + value);
} catch (SerializationException e) {
  System.out.println("Deserialization error caught");
}
APrints "Deserialization error caught" when a corrupted message is read
BThrows an uncaught exception and stops the consumer
CPrints "Received: <message>" for all messages, including corrupted ones
DSkips corrupted messages silently without any output
Attempts:
2 left
💡 Hint
Think about how exceptions in deserialization are handled inside the try-catch block.
Predict Output
intermediate
2:00remaining
What happens if a Kafka producer's send callback reports a network error?
A Kafka producer sends a message asynchronously with a callback that checks for exceptions. What will the callback print if the network is down during send?
Kafka
producer.send(new ProducerRecord<>("topic", "key", "value"), (metadata, exception) -> {
  if (exception != null) {
    System.out.println("Send failed: " + exception.getClass().getSimpleName());
  } else {
    System.out.println("Send succeeded");
  }
});
APrints "Send failed: TimeoutException" or a related network error
BDoes not print anything because callback is not called
CThrows an exception outside the callback
DPrints "Send succeeded" even if network is down
Attempts:
2 left
💡 Hint
The callback receives an exception parameter when send fails.
🧠 Conceptual
advanced
2:00remaining
Which error handling strategy prevents message loss in Kafka consumers?
You want to ensure no messages are lost even if processing fails. Which approach is best for error handling in Kafka consumers?
AUse auto-commit with a short interval
BCommit offsets immediately after polling messages
CIgnore exceptions and continue processing next messages
DCommit offsets only after successful processing of messages
Attempts:
2 left
💡 Hint
Think about when to commit offsets to avoid losing unprocessed messages.
Predict Output
advanced
2:00remaining
What error does this Kafka consumer code raise?
Analyze the following Kafka consumer code snippet and identify the error it raises at runtime.
Kafka
consumer.subscribe(Collections.singletonList("topic"));
while (true) {
  ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
  for (ConsumerRecord<String, String> record : records) {
    System.out.println(record.value().toUpperCase());
  }
  consumer.commitSync();
}
consumer.close();
AIllegalStateException because consumer.close() is unreachable
BNoSuchElementException when records is empty
CNo error, prints all messages in uppercase
DCommitFailedException if commitSync is called without subscription
Attempts:
2 left
💡 Hint
Consider the code flow and whether it raises a runtime exception.
🧠 Conceptual
expert
3:00remaining
How to handle poison pill messages in Kafka consumers to avoid infinite processing loops?
A poison pill message causes your consumer to fail processing repeatedly. What is the best error handling approach to avoid infinite retries on such messages?
ASkip the message by committing the offset and log the error
BUse a dead-letter queue to move poison pill messages after retries
CStop the consumer immediately on first failure
DIgnore errors and keep retrying indefinitely
Attempts:
2 left
💡 Hint
Think about how to isolate bad messages without losing them.