0
0
Kafkadevops~30 mins

In-sync replicas (ISR) in Kafka - Mini Project: Build & Apply

Choose your learning style9 modes available
In-sync Replicas (ISR) in Kafka
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Use a simple for loop to print each message in the list.