When a product-price change matters, the producer should know more than whether one broker received it. With acks=all, the partition leader acknowledges the write only after every in-sync replica (ISR) has persisted it. The equivalent setting is acks=-1. section 5.1.1 section 5.1.2
Send price changes with all acknowledgment
Run `kafka-console-producer.sh --topic products.prices.changelog --bootstrap-server localhost:9092 --producer-property acks=all`. The producer waits for the leader’s acknowledgment rather than treating the leader’s receipt alone as confirmation. section 5.1.1
The acknowledgment choice trades confirmation for speed:
- With acks=1, the leader responds as soon as it receives the message. The response is faster, but a leader failure before follower replication can lose an acknowledged write. section 5.1.1
- With acks=0, the producer does not wait for confirmation. It offers higher performance when lost messages are tolerable, but cannot confirm that a message arrived. section 5.1.1
All acknowledgment works with the topic setting min.insync.replicas. Set it to the minimum number of replicas that must be in sync for an acknowledged write. If fewer are available, the producer receives an error and retries; acks=all does not mean a write succeeds regardless of broker failures. For example, with a replication factor of three and min.insync.replicas=2, one broker can fail without stopping producers. After a second fails, producers using acks=all cannot produce, although consumers can continue while a leader remains available. section 5.1.2 section 16.1.2
$ kafka-console-producer.sh \
--topic products.prices.changelog.min-isr-2 \
--bootstrap-server localhost:9092 \
--producer-property acks=all
>cola all
>[…] WARN [Producer clientId=console-producer] Got error produce response
with correlation id 10 on topic-partition
products.prices.changelog.min-isr-2-2, retrying (2 attempts left).
Error: NOT_ENOUGH_REPLICAS
(org.apache.kafka.clients.producer.internals.Sender)
[…] WARN [Producer clientId=console-producer] Got error produce response
with correlation id 11 on topic-partition
products.prices.changelog.min-isr-2-2, retrying (1 attempts left).
Error: NOT_ENOUGH_REPLICAS
(org.apache.kafka.clients.producer.internals.Sender)
[…] WARN [Producer clientId=console-producer] Got error produce response
with correlation id 12 on topic-partition
products.prices.changelog.min-isr-2-2, retrying (0 attempts left).
Error: NOT_ENOUGH_REPLICAS
(org.apache.kafka.clients.producer.internals.Sender)
[…] ERROR Error when sending message to topic
products.prices.changelog.min-isr-2 with key: null, value: 8 bytes with
error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.NotEnoughReplicasException: Messages are
rejected since there are fewer in-sync replicas than required.
This producer run shows NOT_ENOUGH_REPLICAS retries after the available ISR count falls below a topic’s minimum of two. It makes the availability limit visible at the command line. section 5.1.2
A successful write can still be duplicated: if the data is persisted but its ACK is lost, the producer may resend it. That makes acks=all with a suitable minimum ISR an at-least-once choice, not by itself an exactly-once solution. For transactions where duplicates matter, enable producer idempotence as an additional precaution. Also handle delivery failures: after its delivery timeout, the producer stops retrying and throws an exception. section 5.1.3 section 8.1.3
