Producer can fail to produce the event due to out of the date partition or topic metadata information. I was reading about metadata.max.age.ms Parameter in KafkaProducer/KafkaConsumer. Keeping metadata.max.age.ms property as low as possible will allow more frequent refresh of metadata which means more chances to have latest information of partition/topic.
But just wanted to check if there is another better way to handle this. Is it possible to catch the org.apache.kafka.common.errors.NotLeaderOrFollowerException exception and call some API on demand to enforce the refresh of metadata.