📖 Scenario: You are managing a Kafka cluster that replicates messages across multiple brokers to keep data safe. You want to understand which replicas are currently in-sync with the leader to ensure data reliability.
🎯 Goal: Build a simple Kafka script that lists the in-sync replicas (ISR) for a given topic partition.
📋 What You'll Learn
Create a dictionary called topic_partitions with one entry: key 'my_topic-0' and value {'replicas': [1, 2, 3], 'leader': 1, 'isr': [1, 2]}
Create a variable called partition_key and set it to 'my_topic-0'
Use a for loop with variable replica to iterate over the replicas and check if each is in the ISR list
Create a list called replica_status that stores strings like 'Replica 1 is in-sync' or 'Replica 3 is out-of-sync'
Print each string in replica_status on a new line
💡 Why This Matters
🌍 Real World
Kafka uses in-sync replicas to ensure data is safely replicated across brokers. Monitoring ISR helps maintain data durability and availability.
💼 Career
Understanding ISR is important for roles like Kafka administrators, DevOps engineers, and backend developers working with distributed systems.
Progress0 / 4 steps
1
Create the topic partition data
Create a dictionary called topic_partitions with one entry: key 'my_topic-0' and value {'replicas': [1, 2, 3], 'leader': 1, 'isr': [1, 2]}
Kafka
Hint
Think of topic_partitions as a map where the key is the topic and partition, and the value is another map with replica info.
2
Set the partition key
Create a variable called partition_key and set it to 'my_topic-0'
Kafka
Hint
This variable will help us access the data for the specific partition.
3
Check which replicas are in-sync
Use a for loop with variable replica to iterate over the replicas in topic_partitions[partition_key]['replicas'] and check if each replica is in topic_partitions[partition_key]['isr']. Create a list called replica_status that stores strings like 'Replica 1 is in-sync' or 'Replica 3 is out-of-sync'
Kafka
Hint
Loop over each replica and check if it is in the ISR list. Use an f-string to create the status message.
4
Print the replica sync status
Print each string in the replica_status list on a new line using a for loop
Kafka
Hint
Use a simple for loop to print each message in the list.
Practice
(1/5)
1. What does In-sync replicas (ISR) mean in Kafka?
easy
A. Replicas that are offline
B. Replicas that never receive data
C. Replicas that have the latest data from the leader
D. Replicas that only store old data
Solution
Step 1: Understand the role of ISR
ISR are replicas that keep up-to-date with the leader's data.
Step 2: Compare options
Only Replicas that have the latest data from the leader correctly describes ISR as replicas with the latest data.
Final Answer:
Replicas that have the latest data from the leader -> Option C
Quick Check:
ISR = Latest data replicas [OK]
Hint: ISR means replicas fully caught up with leader data [OK]
Common Mistakes:
Thinking ISR includes offline replicas
Confusing ISR with replicas that lag behind
Assuming ISR means replicas with old data
2. Which Kafka configuration controls the minimum number of ISR replicas required to acknowledge a write?
easy
A. replica.fetch.max.bytes
B. min.insync.replicas
C. max.insync.replicas
D. offsets.retention.minutes
Solution
Step 1: Identify configuration related to ISR acknowledgments
The setting min.insync.replicas defines the minimum ISR count for write success.
Step 2: Eliminate unrelated options
Other options control fetch size or retention, not ISR acknowledgments.
Final Answer:
min.insync.replicas -> Option B
Quick Check:
Minimum ISR replicas = min.insync.replicas [OK]
Hint: min.insync.replicas sets minimum ISR for writes [OK]
Common Mistakes:
Confusing min.insync.replicas with max.insync.replicas
Choosing unrelated configs like offsets.retention.minutes
Hint: Error means ISR count < min.insync.replicas [OK]
Common Mistakes:
Blaming leader offline instead of ISR count
Confusing consumer group commit with ISR errors
Thinking zero partitions cause this error
5. You want to ensure high availability in Kafka by allowing leader failover only if at least 2 replicas are in ISR. Which configuration and setup achieve this?
hard
A. Set min.insync.replicas=2 and have at least 3 replicas per partition
B. Set min.insync.replicas=1 and have 2 replicas per partition
C. Set min.insync.replicas=3 with 2 replicas per partition
D. Set min.insync.replicas=0 and 1 replica per partition
Solution
Step 1: Understand min.insync.replicas meaning
This setting defines the minimum ISR count required for leader failover and write success.
Step 2: Match configuration to requirement
To require at least 2 ISR replicas, set min.insync.replicas=2 and have at least 3 replicas to allow failover.
Final Answer:
Set min.insync.replicas=2 and have at least 3 replicas per partition -> Option A
Quick Check:
High availability needs min.insync.replicas=2 with 3 replicas [OK]
Hint: min.insync.replicas ≤ replica count for failover [OK]
Common Mistakes:
Setting min.insync.replicas higher than replica count
Using too few replicas for desired availability
Setting min.insync.replicas to zero disables safety
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.