Challenge - 5 Problems
Kafka Leader Election Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this Kafka leader election log snippet?
Given the following Kafka broker log snippet during leader election, what is the final elected leader ID?
Kafka
[2024-06-01 10:00:00] Broker 1: Starting leader election for partition 0 [2024-06-01 10:00:01] Broker 2: Received vote request from Broker 1 [2024-06-01 10:00:02] Broker 3: Voted for Broker 1 [2024-06-01 10:00:03] Broker 2: Voted for Broker 1 [2024-06-01 10:00:04] Broker 1: Leader election complete. Leader is Broker 1
Attempts:
2 left
💡 Hint
Look for the broker that received majority votes.
✗ Incorrect
Broker 1 received votes from Broker 2 and Broker 3, which is a majority, so Broker 1 is elected leader.
🧠 Conceptual
intermediateWhich Kafka component is responsible for leader election?
In Kafka, which component manages the leader election process for partitions?
Attempts:
2 left
💡 Hint
This component coordinates cluster metadata and elections.
✗ Incorrect
The Kafka Controller is a special broker that manages leader election and partition assignments.
🔧 Debug
advancedWhy does this Kafka leader election fail?
Given this simplified code snippet for leader election, why does it fail to elect a leader?
```java
Map votes = new HashMap<>();
votes.put(1, 1);
votes.put(2, 1);
if (votes.values().stream().max(Integer::compare).get() > votes.size() / 2) {
System.out.println("Leader elected");
} else {
System.out.println("No leader");
}
```
Attempts:
2 left
💡 Hint
Check how division works with integers in Java.
✗ Incorrect
votes.size() / 2 does integer division, so for size 2 it equals 1, making the condition incorrect for majority.
📝 Syntax
advancedWhich option correctly implements a Kafka leader election check in Python?
Select the Python code snippet that correctly checks if a candidate has majority votes in a leader election.
Attempts:
2 left
💡 Hint
Majority means strictly more than half using integer division.
✗ Incorrect
Using integer division (//) ensures correct majority check. Option A uses > and // which is correct.
🚀 Application
expertHow many partitions have leaders after this Kafka cluster state update?
Given this Kafka cluster state JSON showing partition leaders, how many partitions currently have a leader assigned?
```json
{
"partitions": [
{"partition": 0, "leader": 1},
{"partition": 1, "leader": -1},
{"partition": 2, "leader": 2},
{"partition": 3, "leader": -1},
{"partition": 4, "leader": 3}
]
}
```
Attempts:
2 left
💡 Hint
Leader -1 means no leader assigned.
✗ Incorrect
Partitions 0, 2, and 4 have leaders (1, 2, 3). Partitions 1 and 3 have leader -1 meaning no leader.
