k314159
k314159

Reputation: 11246

Kafka Producer guarantees

I'm using a Kafka Producer and my application sends individual ProducerRecords all with the same key into a single partition, and these ProducerRecords are then batched (using batch.size and linger.ms parameters) before being sent to the brokers. I have enable.idempotence=true and acks=all.

If one record in the middle of a batch fails to be written, for example if a host crashes or a network failure or disk failure occurs or the record failed to be acked by the minimum replicas, does Kafka guarantee that all subsequent records will also not be written? Or is there a possibility that a record in the middle of a batch could be missing?

Upvotes: 4

Views: 1090

Answers (2)

Michael Heil
Michael Heil

Reputation: 18515

If one record in the middle of a batch fails to be written, for example if a host crashes or a network failure or disk failure occurs or the record failed to be acked by the minimum replicas, does Kafka guarantee that all subsequent records will also not be written?

Yes, if any message within a batch fails, then all messages in the same batch fail. So none of the messages within the batch will be written to the broker's disk.

Or is there a possibility that a record in the middle of a batch could be missing?

No, either all or none messages of the batch are written to the broker.

This is achieved by the separation between the Producer client thread and a local buffer that queues and batches the data before sending it physically to the broker.

Upvotes: 3

Rishabh Sharma
Rishabh Sharma

Reputation: 862

Since your records are all going to the same partition, you can safely assume all previous records will also be there.

Kafka guarantees ordering in a given partition, so if you are sending messages m1 and m2 (in order) to the partition, the batch and linger logic will not override the ordering. In other words, if you see the message m2 at your consumer, you can safely assume that m1 was delivered safely as well.

Upvotes: 1

Related Questions