Bird
Raised Fist0
Kafkadevops~20 mins

Event streaming concept in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kafka Event Streaming 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 producer code snippet?

Consider this Kafka producer code in Java that sends a message to a topic named test-topic. What will be printed on the console?

Kafka
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

Producer<String, String> producer = new KafkaProducer<>(props);
ProducerRecord<String, String> record = new ProducerRecord<>("test-topic", "key1", "Hello Kafka");
producer.send(record, (metadata, exception) -> {
    if (exception == null) {
        System.out.println("Sent to partition " + metadata.partition());
    } else {
        System.out.println("Error sending message");
    }
});
producer.close();
ASent to partition 0
BError sending message
CSent to partition 1
DNo output
Attempts:
2 left
💡 Hint

Assume the topic test-topic has only one partition.

🧠 Conceptual
intermediate
1:30remaining
What does Kafka's consumer group ensure?

In Kafka, what is the main purpose of a consumer group?

ATo allow multiple consumers to read the same message independently
BTo distribute partitions among consumers for parallel processing
CTo store messages permanently in Kafka topics
DTo encrypt messages during transmission
Attempts:
2 left
💡 Hint

Think about how Kafka balances workload among consumers.

🔧 Debug
advanced
2:30remaining
Why does this Kafka consumer code fail to receive messages?

Look at this Kafka consumer code snippet. It never prints any consumed messages. What is the cause?

Kafka
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "group1");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");

KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Collections.singletonList("my-topic"));

while (true) {
    ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
    for (ConsumerRecord<String, String> record : records) {
        System.out.println("Received: " + record.value());
    }
}
AThe consumer does not call consumer.close(), causing resource leak
BThe consumer group ID is missing, causing subscription failure
CThe consumer never commits offsets, so it reads no messages
DThe consumer does not call poll() correctly to fetch messages
Attempts:
2 left
💡 Hint

Check the poll method usage and its parameters.

📝 Syntax
advanced
1:30remaining
Which Kafka Streams code snippet compiles without error?

Which of these Kafka Streams Java code snippets correctly creates a stream from topic input-topic?

A
StreamsBuilder builder = new StreamsBuilder();
KStream&lt;String, String&gt; stream = builder.stream("input-topic");
B
StreamsBuilder builder = new StreamsBuilder()
KStream&lt;String, String&gt; stream = builder.stream("input-topic")
C
StreamsBuilder builder = new StreamsBuilder();
KStream&lt;String, String&gt; stream = builder.stream(input-topic);
D
StreamsBuilder builder = new StreamsBuilder();
KStream&lt;String, String&gt; stream = builder.stream('input-topic');
Attempts:
2 left
💡 Hint

Check for correct Java syntax and string literals.

🚀 Application
expert
2:00remaining
How many partitions will be assigned to each consumer in this group?

A Kafka topic has 6 partitions. There are 3 consumers in the same consumer group subscribed to this topic. How many partitions will each consumer get assigned?

AEach consumer gets 3 partitions
BEach consumer gets 1 partition
CEach consumer gets 2 partitions
DAll consumers get all 6 partitions
Attempts:
2 left
💡 Hint

Partitions are divided evenly among consumers in a group.

Practice

(1/5)
1. What is the main purpose of event streaming in Kafka?
easy
A. To batch process data once a day
B. To store data permanently in a database
C. To create static reports from data
D. To send data as it happens for real-time updates

Solution

  1. Step 1: Understand event streaming concept

    Event streaming means sending data continuously as events happen, not waiting to batch or store permanently.
  2. Step 2: Match purpose with options

    Only To send data as it happens for real-time updates describes sending data as it happens for real-time updates, which is the core of event streaming.
  3. Final Answer:

    To send data as it happens for real-time updates -> Option D
  4. Quick Check:

    Event streaming = real-time data flow [OK]
Hint: Event streaming means data flows live, not stored or batched [OK]
Common Mistakes:
  • Confusing event streaming with batch processing
  • Thinking event streaming stores data permanently
  • Assuming event streaming creates static reports
2. Which of the following is the correct way to describe a Kafka producer?
easy
A. A database that stores events permanently
B. A component that reads events from topics
C. A component that sends events to topics
D. A tool that visualizes event data

Solution

  1. Step 1: Define Kafka producer role

    A Kafka producer is the part that sends or writes events into Kafka topics.
  2. Step 2: Compare options with definition

    A component that sends events to topics correctly states the producer sends events to topics; others describe consumers, databases, or tools.
  3. Final Answer:

    A component that sends events to topics -> Option C
  4. Quick Check:

    Producer = sends events [OK]
Hint: Producer sends events; consumer reads events [OK]
Common Mistakes:
  • Mixing up producer and consumer roles
  • Thinking producer stores data permanently
  • Confusing producer with visualization tools
3. Given this Kafka event flow: Producer sends events to topic 'orders'. Consumer reads from 'orders'. What happens if the consumer is slow?
medium
A. Events are lost immediately
B. Events accumulate in the topic until consumed
C. Producer stops sending events
D. Topic deletes old events instantly

Solution

  1. Step 1: Understand Kafka topic behavior

    Kafka stores events in topics until consumers read them; slow consumers cause events to accumulate.
  2. Step 2: Analyze options based on behavior

    Events accumulate in the topic until consumed matches this behavior; events wait in topic. Events are not lost immediately, producer keeps sending, and topic deletes old events only after retention period.
  3. Final Answer:

    Events accumulate in the topic until consumed -> Option B
  4. Quick Check:

    Slow consumer = event backlog in topic [OK]
Hint: Slow consumer causes event backlog, not loss [OK]
Common Mistakes:
  • Assuming events are lost if consumer is slow
  • Thinking producer stops sending events
  • Believing topics delete events instantly
4. You wrote a Kafka consumer but it never receives any events. Which is the most likely mistake?
medium
A. The consumer is subscribed to the wrong topic
B. The producer is sending events correctly
C. The topic has too many partitions
D. The consumer is reading from the correct topic

Solution

  1. Step 1: Identify why consumer gets no events

    If a consumer never receives events, a common cause is subscribing to the wrong topic.
  2. Step 2: Evaluate options

    The consumer is subscribed to the wrong topic points to wrong topic subscription, which explains no events. Other options do not explain lack of events.
  3. Final Answer:

    The consumer is subscribed to the wrong topic -> Option A
  4. Quick Check:

    No events = wrong topic subscription [OK]
Hint: Check consumer topic subscription first [OK]
Common Mistakes:
  • Ignoring topic subscription errors
  • Blaming producer when it sends correctly
  • Confusing topic partitions with event delivery
5. You want to build a real-time dashboard that updates instantly when new sales happen. Which Kafka setup best supports this?
hard
A. Producer sends sales events to a topic; consumer reads and updates dashboard immediately
B. Producer batches sales events daily; consumer reads once a day
C. Producer sends events to multiple unrelated topics; consumer reads only one
D. Consumer writes sales events back to producer

Solution

  1. Step 1: Identify real-time update needs

    A real-time dashboard requires events sent and consumed instantly to update live.
  2. Step 2: Match Kafka setup to real-time flow

    Producer sends sales events to a topic; consumer reads and updates dashboard immediately describes producer sending events to a topic and consumer reading immediately to update dashboard, fitting real-time needs.
  3. Step 3: Eliminate other options

    Producer batches sales events daily; consumer reads once a day is batch, not real-time; C is inconsistent topic usage; D is incorrect flow direction.
  4. Final Answer:

    Producer sends sales events to a topic; consumer reads and updates dashboard immediately -> Option A
  5. Quick Check:

    Real-time dashboard = immediate event flow [OK]
Hint: Real-time needs immediate produce and consume flow [OK]
Common Mistakes:
  • Choosing batch processing for real-time needs
  • Using multiple unrelated topics incorrectly
  • Confusing producer and consumer roles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard