IntermediateInternals
How does a Kafka producer handle a NOT_LEADER_OR_FOLLOWER error?
Reference answer
When the producer sends to a broker that is not the current leader for a partition (stale metadata), the broker returns NOT_LEADER_OR_FOLLOWER. The producer: 1) Marks its metadata cache for that partition as stale. 2) Triggers a metadata refresh request to a bootstrap broker. 3) Retries the produce request with updated leader info after retry.backoff.ms. With enable.idempotence=true and sequence numbers, the retry won't create duplicates even if the original request actually succeeded. This automatic recovery makes Kafka producers resilient to leader elections.
Expected key concepts: NOT_LEADER_OR_FOLLOWER, stale metadata, metadata refresh, retry, retry.backoff.ms, enable.idempotence, sequence numbers, automatic recovery, leader election