A metadata request lets a Kafka producer discover which brokers lead each partition. The producer uses this broker-to-partition mapping to send records directly to the correct partition leaders rather than routing blindly through the cluster. section 3.2
Because leadership changes infrequently, the producer caches the mapping. The metadata.max.age.ms setting controls refresh timing and defaults to five minutes. A leadership change can make cached routing stale; the broker returns an error, after which the client refreshes metadata and retries the batch. section 3.2 section 2.3.1
Handling a partition-leader change
Suppose a producer has cached partition leadership and sends a batch to the former leader. That broker reports that leadership has changed. The client library retrieves current metadata, identifies the newly elected leader, and resends the batch; the temporary error is recorded in the application log. section 3.2 section 2.3.1
Figure 3.6 The process of receiving and caching metadata
Shows the request, broker mapping, producer-side cache, and metadata refresh cycle. section 3.2

