0
0
Kafkadevops~20 mins

Auto-scaling strategies in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Auto-Scaling 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 consumer group scaling code?
Consider a Kafka consumer group with 3 consumers consuming from 3 partitions. The code below simulates scaling the consumers dynamically. What will be the number of active consumers after running this code?
Kafka
consumers = 3
partitions = 3

# Simulate scaling down by 1 consumer
consumers -= 1

# Simulate scaling up by 2 consumers
consumers += 2

# But max consumers cannot exceed partitions
active_consumers = min(consumers, partitions)
print(active_consumers)
A3
B1
C2
D4
Attempts:
2 left
💡 Hint
Remember that the number of active consumers cannot exceed the number of partitions.
🧠 Conceptual
intermediate
1:30remaining
Which auto-scaling metric is best for Kafka consumer groups?
You want to auto-scale Kafka consumers based on workload. Which metric is most appropriate to trigger scaling?
ANumber of active partitions
BConsumer lag (messages behind)
CCPU usage of consumer machines
DNetwork bandwidth usage
Attempts:
2 left
💡 Hint
Think about what indicates consumers are falling behind.
🔧 Debug
advanced
2:30remaining
Why does this Kafka auto-scaling script fail to scale down?
This Python script tries to scale down Kafka consumers when lag is low, but consumers never decrease. What is the bug?
Kafka
consumers = 5
lag = 0

if lag < 10:
    consumers = consumers - 1
else:
    consumers = consumers + 1

print(consumers)
AThe script does not check if consumers go below 1
BThe condition should be lag <= 10 instead of lag < 10
CThe print statement is outside the if block
DThe lag variable is never updated dynamically
Attempts:
2 left
💡 Hint
Check if lag changes during the script execution.
📝 Syntax
advanced
1:30remaining
Which option correctly implements a Kafka consumer auto-scaling check in Python?
Select the code snippet that correctly checks if consumer lag exceeds threshold and triggers scale up.
A
if lag &gt; threshold
    scale_up()
B
if (lag &gt; threshold)
    scale_up()
C
if lag &gt; threshold:
    scale_up()
D
if lag &gt; threshold then
    scale_up()
Attempts:
2 left
💡 Hint
Remember Python requires a colon after if condition.
🚀 Application
expert
3:00remaining
How many consumers will be active after this auto-scaling logic runs?
Given 4 partitions and initial 2 consumers, the code below scales consumers based on lag values. What is the final number of active consumers?
Kafka
partitions = 4
consumers = 2
lag_values = [5, 15, 8, 20]

for lag in lag_values:
    if lag > 10:
        consumers += 1
    elif lag < 5 and consumers > 1:
        consumers -= 1

active_consumers = min(consumers, partitions)
print(active_consumers)
A4
B2
C3
D5
Attempts:
2 left
💡 Hint
Count how many times consumers increase or decrease, then cap by partitions.