What is acks configuration in a Kafka producer and what do 0, 1, and all mean?
Understand the Kafka producer acks setting and what acks=0, acks=1 and acks=all mean for durability, throughput and preventing data loss.
Expected Interview Answer
The acks setting tells a Kafka producer how many broker acknowledgements it must receive before treating a write as successful: acks=0 waits for none, acks=1 waits for the leader only, and acks=all waits for all in-sync replicas.
acks=0 gives the highest throughput but no delivery guarantee — the producer never waits and can silently lose messages if the broker is down. acks=1 waits for the leader to write the record to its log, which loses data only if the leader fails before followers replicate it. acks=all (also written acks=-1) waits until every in-sync replica has the record, giving the strongest durability, and combined with min.insync.replicas it is the setting used for exactly-once and no-data-loss pipelines. The choice is a direct trade-off between latency/throughput and durability.
- Lets you tune the trade-off between speed and durability
- acks=all prevents data loss on leader failure
- acks=0 maximizes throughput for lossy-tolerant data
- Works with min.insync.replicas to enforce guarantees
- Enables idempotent and exactly-once producer semantics
AI Mentor Explanation
Think of acks as how a runner confirms a run is safely completed. acks=0 is sprinting without ever looking at the crease — fast, but you might be run out and never know. acks=1 is grounding your bat past one crease line and trusting it counts. acks=all is waiting for both the umpire and the scorer to signal the run is recorded before you relax, guaranteeing it can never be wiped from the scorebook.
Step-by-Step Explanation
Step 1
Producer sends a record
The producer batches and sends records to the leader broker of the target partition.
Step 2
acks=0 path
The producer does not wait for any response and immediately considers the send done — fastest, but messages can be lost.
Step 3
acks=1 path
The leader writes the record to its log and responds; the producer proceeds once the leader confirms.
Step 4
acks=all path
The leader waits until all in-sync replicas have replicated the record, then acknowledges — strongest durability.
Step 5
Combine with min.insync.replicas
Set min.insync.replicas so acks=all fails fast if too few replicas are in sync, preventing silent under-replication.
What Interviewer Expects
- Correct meaning of acks=0, acks=1 and acks=all
- Understanding of the durability vs throughput trade-off
- Awareness that acks=all pairs with min.insync.replicas
- Knowledge that acks=all is required for no-data-loss guarantees
- Mention that acks=-1 is the same as acks=all
Common Mistakes
- Thinking acks=all waits for every replica rather than only in-sync replicas
- Believing acks=1 guarantees no data loss
- Ignoring min.insync.replicas, which makes acks=all meaningless if set to 1
- Assuming acks=0 is safe for important data
Best Answer (HR Friendly)
“The acks setting decides how careful a Kafka producer is before saying a message was delivered. Zero means don't wait and risk losing it, one means wait for the main server, and all means wait for every backup copy — trading a little speed for the strongest safety.”
Code Example
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
// Wait for all in-sync replicas to acknowledge — strongest durability
props.put("acks", "all");
props.put("enable.idempotence", "true"); // prevents duplicates on retry
props.put("retries", "3");
KafkaProducer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("orders", "order-42", "created"));
producer.close();Follow-up Questions
- How does min.insync.replicas interact with acks=all?
- What is producer idempotence and why enable it with acks=all?
- Which acks setting would you pick for high-volume metrics data?
- What happens with acks=1 if the leader fails right after acknowledging?
- How does acks relate to at-least-once vs exactly-once semantics?
MCQ Practice
1. What does acks=all wait for before acknowledging a write?
acks=all waits until every in-sync replica has replicated the record, giving the strongest durability guarantee.
2. Which acks value offers the highest throughput with the weakest guarantee?
acks=0 never waits for a broker response, maximizing throughput but risking silent message loss.
3. acks=all is most effective when combined with which setting?
min.insync.replicas ensures a minimum number of in-sync replicas exist, so acks=all actually enforces durability.
Flash Cards
What does acks=0 mean? — The producer does not wait for any broker acknowledgement — fastest but messages can be lost.
What does acks=1 mean? — The producer waits for the leader to write the record; data is lost only if the leader fails before replication.
What does acks=all mean? — The producer waits until all in-sync replicas have the record — strongest durability. Same as acks=-1.
Why pair acks=all with min.insync.replicas? — It guarantees a minimum number of replicas are in sync, so a write fails fast instead of silently being under-replicated.
Continue Learning
Related Interview Questions
How does Kafka achieve durability with replication and the ISR?
hard
What is idempotent producer in Kafka and how does it prevent duplicates?
medium
What are the different delivery semantics in Kafka (at-most-once, at-least-once, exactly-once)?
hard
What is a Kafka partition and why is it the unit of parallelism?
medium