📖 Scenario: You work for a company that uses Apache Kafka to handle real-time data streams. To keep the system safe from failures, you need to plan how to recover data if something goes wrong.This project will guide you through creating a simple Kafka topic setup with replication and configuring a consumer group to read messages safely, which are key parts of disaster recovery planning.
🎯 Goal: Build a basic Kafka setup with a topic that has replication enabled and a consumer group that reads messages reliably. This setup helps ensure data is not lost and can be recovered if a server fails.
📋 What You'll Learn
Create a Kafka topic named orders with 3 partitions and replication factor 2
Set a configuration variable consumer_group with the value order_processors
Write a Kafka consumer that subscribes to the orders topic using the consumer_group
Print the consumed messages to the console
💡 Why This Matters
🌍 Real World
Kafka is widely used in industries like finance, retail, and tech to process data streams reliably. Disaster recovery planning ensures data is safe and systems can recover quickly from failures.
💼 Career
Understanding Kafka topic replication and consumer groups is essential for roles like data engineer, site reliability engineer, and backend developer working with real-time data pipelines.
Progress0 / 4 steps
1
Create Kafka topic with replication
Create a Kafka topic named orders with 3 partitions and a replication factor of 2 using the kafka-topics.sh command.
Kafka
Hint
Use the kafka-topics.sh tool with the --create option and specify the topic name, partitions, and replication factor.
2
Set consumer group variable
Create a variable called consumer_group and set it to the string order_processors.
Kafka
Hint
Assign the string 'order_processors' to the variable consumer_group.
3
Write Kafka consumer subscribing to topic
Write a Kafka consumer in Python that subscribes to the orders topic using the consumer_group variable. Use the KafkaConsumer class from the kafka library and set the group_id to consumer_group.
Kafka
Hint
Import KafkaConsumer and create a consumer subscribing to the orders topic with the group ID set to consumer_group.
4
Print consumed messages
Write a for loop to read messages from the consumer and print each message's value decoded as UTF-8.
Kafka
Hint
Use a for loop to read messages from the consumer and print the decoded message values.
Practice
(1/5)
1. What is the main purpose of disaster recovery planning in Kafka?
easy
A. To keep Kafka data safe and services running after failures
B. To improve Kafka message throughput
C. To reduce Kafka cluster size
D. To speed up Kafka consumer processing
Solution
Step 1: Understand disaster recovery goal
Disaster recovery planning focuses on protecting data and maintaining service availability during failures.
Step 2: Match goal to options
Only To keep Kafka data safe and services running after failures mentions keeping data safe and services running after problems, which matches the goal.
Final Answer:
To keep Kafka data safe and services running after failures -> Option A
Quick Check:
Disaster recovery = data safety and uptime [OK]
Hint: Disaster recovery means data safety and uptime [OK]
Common Mistakes:
Confusing disaster recovery with performance tuning
Thinking it reduces cluster size
Assuming it speeds up consumers
2. Which Kafka feature is used to replicate data to a backup cluster for disaster recovery?
easy
A. Kafka Connect
B. Kafka Streams
C. MirrorMaker
D. Kafka Producer
Solution
Step 1: Identify replication tool for backup clusters
MirrorMaker is designed to copy data between Kafka clusters for backup and disaster recovery.
Step 2: Compare options
Kafka Connect is for data integration, Kafka Streams for processing, and Producer for sending data, so only MirrorMaker fits replication to backup clusters.
Final Answer:
MirrorMaker -> Option C
Quick Check:
Replication to backup = MirrorMaker [OK]
Hint: MirrorMaker copies data between clusters [OK]
Common Mistakes:
Choosing Kafka Connect which is for integration, not replication
Confusing Kafka Streams with replication
Thinking Kafka Producer replicates data
3. Given the following MirrorMaker command, what is its purpose?