Common Exceptions when retries = 0 - srivalligade04/ConfluentExamPreparationNotes GitHub Wiki

If retries=0 is set in a Kafka producer, it means the producer will not retry sending a message if the initial attempt fails. In this case, any transient or recoverable error during the send will immediately result in an exception being thrown to the client.

Common Exceptions When retries=0

Here are some typical exceptions you might encounter:

  1. TimeoutException Cause: The broker did not respond within the configured request.timeout.ms. Example: Network latency, broker overload.
  2. NotLeaderForPartitionException Cause: The broker the producer contacted is no longer the leader for the partition. Normally retriable, but with retries=0, it fails immediately.
  3. NetworkException / IOException Cause: Network issues, such as dropped connections or DNS failures.
  4. UnknownTopicOrPartitionException Cause: The topic or partition doesn’t exist or metadata is outdated.
  5. RecordTooLargeException Cause: The message exceeds the broker’s max.message.bytes or topic limit. Not retriable, even if retries were enabled.
  6. SerializationException Cause: Error during key/value serialization. Always fatal, not retried.

Why This Matters

Setting retries=0 is risky in production because:

  • Transient issues (like leader changes or brief network hiccups) will cause message loss.
  • You lose Kafka’s built-in resilience.

Best Practice

  • retries=5  # or higher
  • enable.idempotence=true  # for safe retries without duplicates