Bird
Raised Fist0
Kafkadevops~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does at-least-once delivery guarantee in Kafka?
easy
A. Messages are delivered only once and never retried
B. Messages are delivered exactly once with no duplicates
C. Messages are never lost but might be delivered more than once
D. Messages might be lost but never duplicated

Solution

  1. Step 1: Understand delivery guarantees

    At-least-once means Kafka ensures messages reach the consumer at least once, so no loss occurs.
  2. Step 2: Consider duplicates possibility

    Because retries can happen, duplicates may occur, so messages might be delivered multiple times.
  3. Final Answer:

    Messages are never lost but might be delivered more than once -> Option C
  4. Quick Check:

    At-least-once = no loss, possible duplicates [OK]
Hint: At-least-once means no loss, duplicates possible [OK]
Common Mistakes:
  • Confusing at-least-once with exactly-once delivery
  • Thinking messages can be lost
  • Assuming no duplicates occur
2. Which Kafka consumer configuration is essential for implementing at-least-once delivery?
easy
A. enable.auto.commit = false
B. enable.auto.commit = true
C. auto.offset.reset = earliest
D. max.poll.records = 1

Solution

  1. Step 1: Identify offset commit behavior

    At-least-once requires manual control of offset commits to avoid losing messages.
  2. Step 2: Choose correct config for manual commit

    Setting enable.auto.commit = false disables automatic commits, allowing manual commits after processing.
  3. Final Answer:

    enable.auto.commit = false -> Option A
  4. Quick Check:

    Manual commit enabled by disabling auto commit [OK]
Hint: Disable auto commit for manual offset control [OK]
Common Mistakes:
  • Leaving auto commit enabled causes possible message loss
  • Confusing auto.offset.reset with commit control
  • Assuming max.poll.records affects delivery guarantee
3. Given this Kafka consumer code snippet, what is the expected behavior regarding message delivery?
consumer.subscribe(['topic'])
for message in consumer:
    process(message)
    consumer.commit()
medium
A. Messages are processed at least once, duplicates possible
B. Messages may be lost if commit happens before processing
C. Messages are processed exactly once with no duplicates
D. Messages are never committed, causing infinite reprocessing

Solution

  1. Step 1: Analyze commit timing

    Commit happens after processing each message, so offsets are saved only after successful processing.
  2. Step 2: Understand delivery guarantee

    If a failure occurs before commit, message will be reprocessed, causing duplicates but no loss.
  3. Final Answer:

    Messages are processed at least once, duplicates possible -> Option A
  4. Quick Check:

    Commit after processing = at-least-once delivery [OK]
Hint: Commit after processing ensures no loss, duplicates possible [OK]
Common Mistakes:
  • Assuming commit before processing
  • Thinking duplicates cannot happen
  • Believing messages are lost on failure
4. Identify the bug in this Kafka consumer code that aims for at-least-once delivery:
consumer.subscribe(['topic'])
for message in consumer:
    consumer.commit()
    process(message)
medium
A. Using subscribe instead of assign causes duplicates
B. Committing offset before processing causes message loss on failure
C. Not committing offsets causes infinite reprocessing
D. process() function is missing a return statement

Solution

  1. Step 1: Check commit position relative to processing

    Offsets are committed before processing, so if processing fails, message is lost.
  2. Step 2: Understand at-least-once requirement

    To guarantee at-least-once, commit must happen after successful processing to avoid loss.
  3. Final Answer:

    Committing offset before processing causes message loss on failure -> Option B
  4. Quick Check:

    Commit after processing to avoid loss [OK]
Hint: Commit offsets only after processing completes [OK]
Common Mistakes:
  • Committing before processing causes data loss
  • Ignoring commit timing importance
  • Confusing subscribe with assign usage
5. You want to ensure at-least-once delivery in Kafka but avoid processing duplicates as much as possible. Which approach best achieves this?
hard
A. Use exactly-once semantics without any manual offset control
B. Enable auto commit and process messages without tracking offsets
C. Commit offsets before processing to speed up throughput
D. Manually commit offsets after processing and implement idempotent processing logic

Solution

  1. Step 1: Combine manual commit with processing logic

    Manual commit after processing ensures no message loss; idempotent logic handles duplicates safely.
  2. Step 2: Evaluate other options

    Auto commit risks loss; committing before processing risks loss; exactly-once semantics require special setup.
  3. Final Answer:

    Manually commit offsets after processing and implement idempotent processing logic -> Option D
  4. Quick Check:

    Manual commit + idempotency = best at-least-once practice [OK]
Hint: Use manual commit plus idempotent processing to reduce duplicates [OK]
Common Mistakes:
  • Relying on auto commit for at-least-once
  • Committing offsets before processing
  • Ignoring idempotent processing importance
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard