Understanding Reliability in Distributed Architecture with Kafka
📖 Scenario: You are working with a messaging system called Kafka, which uses distributed architecture to keep data safe and reliable. Imagine you have a group of friends sharing messages, and if one friend is busy or away, others still keep the messages safe and deliver them.
🎯 Goal: Build a simple Python program that simulates a distributed system with multiple nodes (friends) storing messages. You will create the data, set a threshold for reliability, check which nodes have the message, and print the reliable nodes.
📋 What You'll Learn
Create a dictionary called nodes with 4 nodes and their message counts
Create a variable called reliability_threshold set to 2
Use a dictionary comprehension to create reliable_nodes with nodes having messages >= reliability_threshold
Print the reliable_nodes dictionary
💡 Why This Matters
🌍 Real World
Distributed architecture like Kafka uses multiple nodes to store data so that if one node fails, others still have the data. This keeps systems reliable and available.
💼 Career
Understanding distributed systems and reliability is important for roles in software development, system administration, and data engineering, especially when working with technologies like Kafka.
Progress0 / 4 steps
1
Create the nodes data
Create a dictionary called nodes with these exact entries: 'node1': 3, 'node2': 1, 'node3': 4, 'node4': 0
Kafka
Hint
Think of each node as a friend holding some messages. Use curly braces to create the dictionary.
2
Set the reliability threshold
Create a variable called reliability_threshold and set it to 2
Kafka
Hint
This threshold means a node must have at least 2 messages to be considered reliable.
3
Filter reliable nodes
Use a dictionary comprehension to create a new dictionary called reliable_nodes that includes only nodes from nodes with message counts greater than or equal to reliability_threshold
Kafka
Hint
Use {node: count for node, count in nodes.items() if count >= reliability_threshold} to filter.
4
Print the reliable nodes
Write a print statement to display the reliable_nodes dictionary
Kafka
Hint
Use print(reliable_nodes) to show the result.
Practice
(1/5)
1. Why does Kafka use a distributed architecture with multiple brokers?
easy
A. To ensure data is safe and available even if some machines fail
B. To make the system slower and less efficient
C. To store all data on a single machine for simplicity
D. To avoid using network communication between machines