Bird
Raised Fist0
Kafkadevops~20 mins

Acknowledgment modes (acks=0, 1, all) in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kafka Acknowledgment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output when using acks=0?

Consider a Kafka producer configured with acks=0. What is the expected behavior when sending a message?

Kafka
producer.send('topic', b'message')
print('Message sent')
AThe producer waits for the broker to confirm the message before printing 'Message sent'.
BThe producer retries sending the message until it receives an acknowledgment.
CThe producer sends the message and immediately prints 'Message sent' without waiting for any acknowledgment.
DThe producer raises an error because acks=0 is invalid.
Attempts:
2 left
💡 Hint

Think about what it means to not wait for any acknowledgment from the broker.

❓ Predict Output
intermediate
2:00remaining
What happens with acks=1 when broker is slow?

A Kafka producer is set with acks=1. The broker is slow to respond. What will the producer do?

Kafka
producer.send('topic', b'message')
print('Message sent')
AThe producer waits for the leader broker to acknowledge before printing 'Message sent'.
BThe producer raises a timeout error immediately.
CThe producer waits for all replicas to acknowledge before printing 'Message sent'.
DThe producer does not wait and prints 'Message sent' immediately.
Attempts:
2 left
💡 Hint

Recall what acks=1 means about waiting for acknowledgments.

❓ Predict Output
advanced
2:00remaining
What is the effect of acks=all on message durability?

When a Kafka producer uses acks=all, what is the effect on message durability?

AThe message is considered durable after all in-sync replicas have acknowledged it.
BThe message is sent without waiting for any acknowledgment, so durability is not guaranteed.
CThe message is considered durable only after the leader broker writes it to its local log.
DThe message is durable only if the producer retries sending it multiple times.
Attempts:
2 left
💡 Hint

Think about what all means in the context of acknowledgments.

🧠 Conceptual
advanced
2:00remaining
Which acknowledgment mode risks message loss on broker failure?

Among acks=0, acks=1, and acks=all, which mode has the highest risk of message loss if the broker crashes immediately after receiving the message?

A<code>acks=1</code> because it waits only for the leader broker's acknowledgment.
B<code>acks=0</code> because it does not wait for any acknowledgment.
CAll modes have the same risk of message loss.
D<code>acks=all</code> because it waits for all replicas and can lose messages if replicas are slow.
Attempts:
2 left
💡 Hint

Consider what happens if the producer does not wait for any confirmation.

🔧 Debug
expert
3:00remaining
Why does this Kafka producer hang with acks=all?

A Kafka producer is configured with acks=all and sends a message. The program hangs indefinitely. What is the most likely cause?

Kafka
producer = KafkaProducer(acks='all')
producer.send('topic', b'message')
producer.flush()
AThe topic does not exist, so the producer immediately raises an error.
BThe producer is missing the <code>flush()</code> call, so messages are not sent.
CThe <code>acks</code> parameter is invalid and causes a configuration error.
DThere are no in-sync replicas available, so the producer waits forever for acknowledgments.
Attempts:
2 left
💡 Hint

Think about what acks=all requires from the cluster.

Practice

(1/5)
1. Which acks mode in Kafka provides the fastest message sending but with the least safety?
easy
A. acks=0
B. acks=1
C. acks=all
D. None of the above

Solution

  1. Step 1: Understand acks=0 behavior

    This mode means the producer does not wait for any acknowledgment from the broker, so it sends messages fastest but with no guarantee of delivery.
  2. Step 2: Compare with other modes

    acks=1 waits for leader confirmation, and acks=all waits for all replicas, both slower but safer.
  3. Final Answer:

    acks=0 -> Option A
  4. Quick Check:

    Fastest but least safe = acks=0 [OK]
Hint: No wait for confirmation means fastest mode is acks=0 [OK]
Common Mistakes:
  • Confusing acks=0 with acks=1
  • Thinking acks=all is fastest
  • Assuming acks=0 waits for leader
2. Which of the following is the correct way to set the acknowledgment mode to wait for all replicas in Kafka producer configuration?
easy
A. "acks=1"
B. "acks=0"
C. "acks=all"
D. "ack=all"

Solution

  1. Step 1: Recall correct property name and value

    The property is acks (plural), and to wait for all replicas, the value is all.
  2. Step 2: Check options for syntax correctness

    "acks=all" uses correct key and value: "acks=all". "ack=all" has a typo "ack" instead of "acks".
  3. Final Answer:

    "acks=all" -> Option C
  4. Quick Check:

    Wait for all replicas = acks=all [OK]
Hint: Remember plural 'acks' and value 'all' for all replicas [OK]
Common Mistakes:
  • Using 'ack' instead of 'acks'
  • Confusing 'acks=1' with 'acks=all'
  • Setting 'acks=0' for all replicas
3. Consider this Kafka producer code snippet:
props.put("acks", "1");
producer.send(record);
System.out.println("Message sent");

What does acks=1 guarantee before printing "Message sent"?
medium
A. Message is stored only in producer buffer
B. No guarantee; message may be lost
C. All replicas have confirmed the message
D. Leader broker has confirmed the message

Solution

  1. Step 1: Understand acks=1 meaning

    This mode waits for the leader broker to confirm the message is received and written to its log.
  2. Step 2: Compare with other options

    acks=0 gives no guarantee, acks=all waits for all replicas, and producer buffer storage is unrelated.
  3. Final Answer:

    Leader broker has confirmed the message -> Option D
  4. Quick Check:

    acks=1 means leader confirmation [OK]
Hint: acks=1 waits for leader confirmation only [OK]
Common Mistakes:
  • Thinking acks=1 waits for all replicas
  • Assuming no guarantee with acks=1
  • Confusing producer buffer with broker confirmation
4. You have this Kafka producer configuration:
props.put("acks", "alll");

What is the problem with this configuration?
medium
A. Typo in the value; should be "all"
B. Typo in the key; should be "ack"
C. No problem; "alll" is valid
D. Should be an integer, not a string

Solution

  1. Step 1: Check the value spelling

    The correct value for waiting all replicas is "all", but here it is misspelled as "alll" with an extra 'l'.
  2. Step 2: Verify key and value types

    The key "acks" is correct and the value should be a string. So the problem is only the typo in the value.
  3. Final Answer:

    Typo in the value; should be "all" -> Option A
  4. Quick Check:

    Value must be "all", not "alll" [OK]
Hint: Check spelling of 'all' carefully in acks value [OK]
Common Mistakes:
  • Assuming 'alll' is valid
  • Changing key to 'ack' instead of 'acks'
  • Using integer instead of string for acks
5. You want to ensure maximum data safety in Kafka producer but can tolerate some delay. Which acks setting should you use and why?
hard
A. acks=1 because leader confirmation is enough
B. acks=all because it waits for all replicas
C. acks=0 because it is fastest
D. acks=-1 because it disables acknowledgments

Solution

  1. Step 1: Identify safety vs speed tradeoff

    acks=all waits for all replicas to confirm, ensuring maximum data safety but slower performance.
  2. Step 2: Evaluate other options

    acks=0 is fastest but unsafe, acks=1 waits only for leader, and acks=-1 is invalid or equivalent to acks=all but less clear.
  3. Final Answer:

    acks=all because it waits for all replicas -> Option B
  4. Quick Check:

    Max safety = acks=all [OK]
Hint: Max safety means waiting for all replicas: acks=all [OK]
Common Mistakes:
  • Choosing acks=0 for safety
  • Confusing acks=-1 as disabling acknowledgments
  • Thinking leader confirmation is max safety
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