Recall from previous chapters that a producer can consider a message successfully written by configuring the acks parameter to 0, 1 or all. When acks is set to zero, the client producer registers success as soon as the message is sent without waiting for the brokers to accept it. When acks is set to 1, the sent message is considered successfully written to Kafka if the partition leader accepts the message. Lastly, when acks is set to all, message delivery is considered successful when all in-sync replicas accept the message. The usual flow of a produce request when received by a partition replica is run through a few checks:
Does the producer have write privilege to the topic?
Does the acks parameter have a valid value of 0, 1 or all?
If acks has been set to all, are there enough in-sync replicas to safely write the message? Brokers can refuse to write a message if the number of in-sync replicas is below a configurable number.
Once the message has been accepted, it’ll get written to the local disk. In Linux, the message actually ends up in the filesystem cache and there’s no certainty when the message will get written to disk. Note that if acks has been set to 0 or 1, the partition leader will respond immediately after writing the message. However, if acks is set to all, then the leader will store the request in a buffer called the purgatory and wait to respond to the producer client until it observes that all in-sync replicas have replicated the message.