0
0
Kafkadevops~20 mins

Leader election in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Leader Election Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What 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
ALeader is Broker 2
BLeader is Broker 1
CLeader is Broker 3
DNo leader elected
Attempts:
2 left
💡 Hint
Look for the broker that received majority votes.
🧠 Conceptual
intermediate
1:30remaining
Which Kafka component is responsible for leader election?
In Kafka, which component manages the leader election process for partitions?
AKafka Broker
BKafka Producer
CKafka Consumer
DKafka Controller
Attempts:
2 left
💡 Hint
This component coordinates cluster metadata and elections.
🔧 Debug
advanced
2:30remaining
Why 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"); } ```
AThe condition uses integer division causing incorrect majority check
BThe votes map is empty
CThe max function returns null
DThe map keys are incorrect
Attempts:
2 left
💡 Hint
Check how division works with integers in Java.
📝 Syntax
advanced
2:00remaining
Which 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.
A
votes = {1: 2, 2: 1}
if max(votes.values()) &gt; len(votes) // 2:
    print('Leader elected')
B
votes = {1: 2, 2: 1}
if max(votes.values()) &gt; len(votes) / 2:
    print('Leader elected')
C
votes = {1: 2, 2: 1}
if max(votes.values()) &gt;= len(votes) / 2:
    print('Leader elected')
D
votes = {1: 2, 2: 1}
if max(votes.values()) &gt;= len(votes) // 2:
    print('Leader elected')
Attempts:
2 left
💡 Hint
Majority means strictly more than half using integer division.
🚀 Application
expert
3:00remaining
How 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} ] } ```
A4
B2
C3
D5
Attempts:
2 left
💡 Hint
Leader -1 means no leader assigned.