0
0
Kafkadevops~20 mins

Retention policies (time-based, size-based) in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Retention Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the effect of this retention.ms setting?
Given a Kafka topic configured with retention.ms=60000, what happens to messages older than 60 seconds?
Kafka
kafka-topics.sh --alter --topic example-topic --config retention.ms=60000 --bootstrap-server localhost:9092
AMessages older than 60 seconds are moved to a backup topic.
BMessages are retained indefinitely regardless of age.
CMessages older than 60 seconds are compressed but not deleted.
DMessages older than 60 seconds are deleted automatically.
Attempts:
2 left
💡 Hint
Think about what retention.ms controls in Kafka.
Predict Output
intermediate
1:30remaining
What happens with this retention.bytes setting?
A Kafka topic has retention.bytes=1048576 (1 MB). What happens when the topic size exceeds 1 MB?
Kafka
kafka-topics.sh --alter --topic example-topic --config retention.bytes=1048576 --bootstrap-server localhost:9092
AOldest messages are deleted to keep the topic size under 1 MB.
BNew messages are rejected once the topic size exceeds 1 MB.
CThe topic size grows indefinitely ignoring retention.bytes.
DMessages are archived to disk when size exceeds 1 MB.
Attempts:
2 left
💡 Hint
Consider what retention.bytes limits in Kafka.
🧠 Conceptual
advanced
2:00remaining
Which retention policy combination causes messages to be deleted earliest?
If a Kafka topic has retention.ms=3600000 (1 hour) and retention.bytes=10485760 (10 MB), when are messages deleted?
AMessages are deleted when either 1 hour passes or topic size exceeds 10 MB, whichever comes first.
BMessages are never deleted automatically with both settings set.
CMessages are deleted only when topic size exceeds 10 MB regardless of time.
DMessages are deleted only after 1 hour regardless of size.
Attempts:
2 left
💡 Hint
Think about how Kafka applies retention.ms and retention.bytes together.
Predict Output
advanced
1:30remaining
What error occurs with this retention.ms value?
What happens if you set retention.ms=-1000 for a Kafka topic?
Kafka
kafka-topics.sh --alter --topic example-topic --config retention.ms=-1000 --bootstrap-server localhost:9092
AKafka deletes all messages immediately upon setting retention.ms negative.
BKafka throws a ConfigException due to invalid negative retention.ms value.
CKafka treats negative retention.ms as infinite retention (never delete).
DKafka ignores the retention.ms setting and uses default retention.
Attempts:
2 left
💡 Hint
Consider valid ranges for retention.ms in Kafka.
🧠 Conceptual
expert
2:30remaining
How does Kafka handle retention with log compaction enabled?
If a Kafka topic has both retention.ms=86400000 (1 day) and log compaction enabled, what is the retention behavior?
AKafka deletes all messages after 1 day regardless of compaction.
BKafka ignores retention.ms and only uses log compaction to delete messages.
CKafka deletes messages older than 1 day but retains the latest record for each key indefinitely.
DKafka disables log compaction when retention.ms is set.
Attempts:
2 left
💡 Hint
Think about how log compaction and retention.ms work together.