Bird
0
0

Given the following Kafka producer code snippet:

medium📝 Predict Output Q4 of 15
Kafka - Producers
Given the following Kafka producer code snippet:
props.put("acks", "1");
producer.send(record);

What happens if the leader broker crashes before replicating the message?
AThe producer waits indefinitely for all replicas to acknowledge.
BThe producer retries sending the message until all replicas confirm.
CThe producer considers the message sent successfully, but replicas may not have it.
DThe producer throws an error immediately.
Step-by-Step Solution
Solution:
  1. Step 1: Understand acks=1 behavior

    With acks=1, the producer waits only for the leader's acknowledgment.
  2. Step 2: Consider leader crash before replication

    If the leader crashes before replicating, the producer still considers the message sent because leader ack was received.
  3. Final Answer:

    The producer considers the message sent successfully, but replicas may not have it. -> Option C
  4. Quick Check:

    acks=1 waits leader ack only, risk of lost replicas [OK]
Quick Trick: acks=1 waits leader ack only, replicas may lag [OK]
Common Mistakes:
  • Assuming producer waits for all replicas with acks=1
  • Thinking producer retries automatically on leader crash
  • Believing an error is thrown immediately

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes