liveBook · Manning

Acknowledgment strategy

As explained in Apache Kafka in Action

An acknowledgment strategy is a Kafka producer policy or setting that determines when a broker acknowledges a published message.

A Kafka producer’s acknowledgment strategy decides when a publish request counts as acknowledged. Choose it according to the cost of losing a message versus the latency of waiting for confirmation. Set it with the producer property `acks`. section 5.1.1

The three settings differ in what the producer learns:

  • `acks=all` (also `acks=-1`): the partition leader acknowledges only after all in-sync replicas have received the message. This is the usual choice when the data is important. section 5.1.1 section 8.1.3
  • `acks=1`: the leader acknowledges when it receives the message. The response is faster, but a leader failure before replication can lose the message. section 5.1.1
  • `acks=0`: the producer does not wait for a broker acknowledgment. It offers higher performance but no confirmation that the message arrived or was persisted; use it only when loss is tolerable. section 5.1.1

Configure a producer

To publish price changes while waiting for replication, run `kafka-console-producer.sh --topic products.prices.changelog --bootstrap-server localhost:9092 --producer-property acks=all`. Change the final value to `1` or `0` to try the other strategies. section 5.1.1

`acks=all` also interacts with the topic’s `min.insync.replicas` setting. If too few replicas are in sync, the producer receives an error and retries rather than getting an acknowledgment. A producer waiting for an ACK also retries after a response timeout or broker error; if delivery continues to fail until `delivery.timeout.ms`, it raises an exception for the application to handle. Do not blindly resend after that exception. section 5.1.2 section 8.1.3

$ 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.

See the `acks=all` producer report `NOT_ENOUGH_REPLICAS` and retry when a topic requiring two in-sync replicas has only one. section 5.1.2

How Apache Kafka in Action covers it

How deep it goes
Explains all three ACK modes and tests insufficient replicas, then relates acknowledgments to producer timeouts and retries.
Examples
Demonstrates console-producer settings for three ACK modes and a broker-shutdown test that produces `NOT_ENOUGH_REPLICAS`.
What it assumes
Assumes familiarity with producers and topics while defining in-sync replicas and introducing the three ACK settings.
What you can do after
Operate/configure it with `kafka-console-producer.sh`, and diagnose acknowledgment failures when too few replicas remain in sync.
How it connects
Connects acknowledgment settings to partition leaders, in-sync replicas, minimum in-sync replicas, producer retries, and delivery timeouts.

Also explained in

Compare how 2 books explain acknowledgment strategy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.