There are two types of requests:
Produce Requests: These requests are initiated by producers and consist of messages that producers want to write to a Kafka topic.
Fetch Requests: These requests are initiated by consumers or follower replicas and ask for messages in a topic.
As described earlier, all produce and fetch requests against a partition must be sent to the broker that acts as the partition leader for that partition. If requests are directed to a broker that isn’t the partition leader, the client will receive an error saying “the broker isn’t the partition leader”. This brings up the question of how clients know which broker is the partition leader for which partition?
Clients send another request called the metadata request which consists of topics a client is interested in. The server responds with a list of partitions for each topic, the partition replicas, and the partition leaders. Making the metadata request before every produce or fetch request can be taxing on the system, so clients cache the metadata information. Clients will refresh the metadata information after every meta data.max.age.ms milliseconds or when they receive a “not partition leader” error signaling that the metadata information has changed.