📖 Scenario: You are working for a small online store that wants to track customer orders in real-time. They want to send order events to a system where other parts of the store can react quickly, like updating inventory or sending confirmation emails.
🎯 Goal: Build a simple Kafka event streaming setup where you create a topic, send order events, and consume them to see the live stream of orders.
📋 What You'll Learn
Create a Kafka topic named orders
Produce three order events with exact keys and values
Consume the events from the orders topic
Print the consumed events to show the live stream
💡 Why This Matters
🌍 Real World
Many companies use Kafka to stream live data like orders, logs, or sensor readings so different parts of their system can react quickly.
💼 Career
Understanding Kafka event streaming is important for roles in data engineering, backend development, and real-time analytics.
Progress0 / 4 steps
1
Create the Kafka topic orders
Write the Kafka command to create a topic called orders with 1 partition and a replication factor of 1.
Kafka
Hint
Use the kafka-topics command with --create and specify the topic name, partitions, and replication factor.
2
Produce three order events to the orders topic
Use the Kafka console producer to send these exact three events to the orders topic with keys and values separated by a comma: order1,{'item':'book','quantity':1} order2,{'item':'pen','quantity':3} order3,{'item':'notebook','quantity':2}
Kafka
Hint
Use kafka-console-producer with --property parse.key=true and --property key.separator=, to send key-value pairs.
3
Consume the events from the orders topic
Use the Kafka console consumer to read messages from the orders topic starting from the beginning. Include the message keys in the output.
Kafka
Hint
Use kafka-console-consumer with --from-beginning and --property print.key=true to see keys and values.
4
Print the consumed events to show the live stream
Run the Kafka console consumer command you wrote in Step 3 and show the output exactly as it appears, including keys and values.
Kafka
Hint
The output shows each key and its JSON value separated by a tab.
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
Step 1: Understand event streaming concept
Event streaming means sending data continuously as events happen, not waiting to batch or store permanently.
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.
Final Answer:
To send data as it happens for real-time updates -> Option D
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
Step 1: Define Kafka producer role
A Kafka producer is the part that sends or writes events into Kafka topics.
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.
Final Answer:
A component that sends events to topics -> Option C
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
Step 1: Understand Kafka topic behavior
Kafka stores events in topics until consumers read them; slow consumers cause events to accumulate.
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.
Final Answer:
Events accumulate in the topic until consumed -> Option B
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
Step 1: Identify why consumer gets no events
If a consumer never receives events, a common cause is subscribing to the wrong topic.
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.
Final Answer:
The consumer is subscribed to the wrong topic -> Option A
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
Step 1: Identify real-time update needs
A real-time dashboard requires events sent and consumed instantly to update live.
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.
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.
Final Answer:
Producer sends sales events to a topic; consumer reads and updates dashboard immediately -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.