0
0
Kafkadevops~20 mins

At-least-once delivery in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka At-Least-Once 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 commit example?

Consider a Kafka consumer configured for at-least-once delivery. What will be the output of the following code snippet when consuming messages?

Kafka
from kafka import KafkaConsumer

consumer = KafkaConsumer('my_topic', group_id='group1', enable_auto_commit=False)

for message in consumer:
    print(f"Received: {message.value.decode('utf-8')}")
    consumer.commit()
    break
APrints the first message once and commits offset immediately.
BRaises an error because commit() is called without arguments.
CPrints the first message multiple times without committing offset.
DPrints no messages because auto commit is disabled.
Attempts:
2 left
💡 Hint

Think about what happens when auto commit is disabled and commit() is called manually after processing a message.

🧠 Conceptual
intermediate
1:30remaining
Which Kafka configuration ensures at-least-once delivery?

Which configuration option in Kafka consumer guarantees at-least-once message delivery?

Aenable.auto.commit=true with auto commit interval set to 1 ms
Benable.auto.commit=true with auto commit interval set to 1 hour
Cenable.auto.commit=false and manual commit after processing
Denable.auto.commit=false and never commit offsets
Attempts:
2 left
💡 Hint

At-least-once means messages can be processed more than once but never lost.

🔧 Debug
advanced
2:30remaining
Why does this Kafka consumer cause message loss despite manual commits?

Given the following code, why might some messages be lost even though manual commits are used?

Kafka
consumer = KafkaConsumer('topic', group_id='g1', enable_auto_commit=False)

for msg in consumer:
    process(msg)
    if some_condition():
        consumer.commit()
AThe consumer group id is missing, causing offset commits to fail.
BManual commit is not supported in Kafka consumers.
CThe consumer must call commit_async() instead of commit().
DOffsets are only committed conditionally, so some processed messages are not committed.
Attempts:
2 left
💡 Hint

Think about when offsets are committed in relation to message processing.

📝 Syntax
advanced
2:00remaining
Which option correctly commits offsets after processing in Kafka consumer?

Choose the correct code snippet that commits offsets manually after processing each message.

Kafka
consumer = KafkaConsumer('topic', group_id='g1', enable_auto_commit=False)

for msg in consumer:
    process(msg)
    # commit offset here
Aconsumer.commit()
Bconsumer.commit(offsets={msg.topic: msg.offset})
Cconsumer.commit_async()
Dconsumer.commit(offsets={TopicPartition(msg.topic, msg.partition): OffsetAndMetadata(msg.offset, None)})
Attempts:
2 left
💡 Hint

consumer.commit() without arguments is the standard way to manually commit offsets after processing a message.

🚀 Application
expert
3:00remaining
How to implement at-least-once delivery with Kafka producer and consumer?

You want to ensure at-least-once delivery in a Kafka system. Which combination of producer and consumer settings and code logic achieves this?

AProducer disables retries; consumer commits offsets before processing messages.
BProducer uses acks='all' and retries; consumer disables auto commit and commits offsets after processing each message.
CProducer uses acks=1; consumer never commits offsets.
DProducer uses acks=0; consumer enables auto commit with interval 1000ms.
Attempts:
2 left
💡 Hint

At-least-once means messages are never lost but may be duplicated.