0
0
Kafkadevops~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Streams 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 of this Kafka Streams error handler code?

Consider the following Kafka Streams code snippet that uses a custom error handler. What will be printed when a deserialization error occurs?

Kafka
StreamsBuilder builder = new StreamsBuilder();

builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String())
    .withErrorHandler((context, exception) -> {
        System.out.println("Error in topic: " + context.topic());
        return DeserializationHandlerResponse.CONTINUE;
    }))
    .to("output-topic");

KafkaStreams streams = new KafkaStreams(builder.build(), new Properties());
// Assume a deserialization error occurs on "input-topic"
AException thrown and stream stopped
BError in topic: input-topic
CNo output printed, error ignored silently
DError in topic: output-topic
Attempts:
2 left
💡 Hint

Think about what the error handler prints and which topic it refers to.

🧠 Conceptual
intermediate
1:30remaining
Which error handling strategy stops the Kafka Streams application on error?

Kafka Streams offers different error handling strategies. Which one will cause the application to stop processing when an error occurs?

ALog and continue processing
BIgnore errors silently
CFail fast and stop the application
DRetry indefinitely without stopping
Attempts:
2 left
💡 Hint

Consider which strategy prioritizes safety by stopping on errors.

🔧 Debug
advanced
2:30remaining
Identify the error in this Kafka Streams error handler configuration

Review the following Kafka Streams error handler setup. What is the error that will cause a runtime failure?

Kafka
StreamsBuilder builder = new StreamsBuilder();

builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String())
    .withErrorHandler((context, exception) -> {
        System.out.println("Error in topic: " + context.topic());
        return DeserializationHandlerResponse.FAIL;
    }))
    .to("output-topic");

KafkaStreams streams = new KafkaStreams(builder.build(), new Properties());
streams.start();
AThe error handler returns FAIL but the stream is not closed properly, causing resource leaks
BThe error handler lambda syntax is invalid, causing a compilation error
CThe error handler returns an undefined enum value, causing a runtime exception
DThe error handler does not handle exceptions, causing the stream to crash
Attempts:
2 left
💡 Hint

Think about what happens when FAIL is returned and how the stream lifecycle is managed.

📝 Syntax
advanced
2:00remaining
Which option correctly configures a Kafka Streams error handler for deserialization errors?

Choose the code snippet that correctly sets a deserialization error handler in Kafka Streams.

AConsumed.with(Serdes.String(), Serdes.String()).withErrorHandler((context, ex) -> DeserializationHandlerResponse.CONTINUE);
BConsumed.with(Serdes.String(), Serdes.String()).withErrorHandler { context, ex -> DeserializationHandlerResponse.CONTINUE }
CConsumed.with(Serdes.String(), Serdes.String()).withErrorHandler((context, ex) -> { return DeserializationHandlerResponse.CONTINUE; });
DConsumed.with(Serdes.String(), Serdes.String()).withErrorHandler((context, ex) => DeserializationHandlerResponse.CONTINUE);
Attempts:
2 left
💡 Hint

Recall Java lambda syntax and method chaining style.

🚀 Application
expert
3:00remaining
How many error handler invocations occur for a batch of 3 corrupted messages in Kafka Streams?

Assume a Kafka Streams application processes a batch of 3 messages, all corrupted causing deserialization errors. The error handler is set to CONTINUE after logging. How many times will the error handler be invoked?

A1
BDepends on the number of partitions
C0
D3
Attempts:
2 left
💡 Hint

Think about how Kafka Streams processes each message and triggers error handlers.