How does max.poll.records affect the consumer poll
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a popular distributed streaming platform that efficiently handles real-time data feeds. One crucial aspect of Kafka is its consumer behavior, specifically how it retrieves records from the broker. This process is chiefly governed by the max.poll.records configuration, which directly influences the consumer's performance and reliability.
Understanding max.poll.records
The max.poll.records configuration parameter in Kafka determines the maximum number of records a consumer can fetch in a single call to poll(). By default, this is set to 500. This setting offers a balance between throughput and latency in data processing. By setting this parameter, you can control how much data your Kafka consumer will fetch in one request, which can have significant impacts on both consumer performance and overall system resource usage.
Impact on Consumer Performance
- Throughput: A higher
max.poll.recordsvalue increases the batch size of records fetched. This can enhance throughput by reducing the number of poll calls needed to retrieve a large volume of records. However, if the batch size becomes too large, it could lead to higher memory consumption on the consumer side. - Latency: Lower values of
max.poll.recordsmay contribute to lower latency as smaller amounts of data are processed more frequently. This is crucial in scenarios where real-time processing is required. - Memory Utilization: The setting also impacts consumer memory utilization. A higher value increases the temporary memory requirement to hold the fetched records until they are processed.
- Consumer Liveliness: Kafka uses a heartbeat mechanism to check if a consumer is still active. If processing a large batch of records takes too long, the consumer might fail to send heartbeats in a timely manner, leading to a
Consumer group rebalance. This can be mitigated by adjusting bothmax.poll.recordsandmax.poll.interval.ms.
Balancing max.poll.records with Other Parameters
Configuring max.poll.records should not be done in isolation. Other parameters need consideration:
- max.poll.interval.ms: Defines the maximum time between two poll calls before considering the consumer dead and initiating a rebalance. This must be higher than the time it takes to process the number of records defined in
max.poll.records. - fetch.min.bytes and fetch.max.bytes: These determine the minimum and maximum amount of data the broker will send in response to a fetch request from the consumer, respectively. They need to be set in conjunction with
max.poll.recordsfor efficient bandwidth use.
Practical Example
Consider a scenario where a consumer is processing records, and each record takes about 10ms to process. If max.poll.records is set to 500, a single poll would return up to 500 records, taking approximately 5000ms (5 seconds) to process. If max.poll.interval.ms is less than 5000ms, the consumer might be marked as failed. Thus, adjusting both settings is crucial.
Summary Table
| Parameter | Default Value | Impact on Consumer |
max.poll.records | 500 | Determines batch size fetched per poll, affecting throughput, latency, and memory usage. |
max.poll.interval.ms | 300000 (5 min) | Must be greater than the time to process max.poll.records to avoid premature rebalancing. |
fetch.min.bytes | 1 | Controls the minimum amount of data fetched to optimize network utilization. |
fetch.max.bytes | 52428800 (50MB) | Limits the total size of data fetched in one request, aligning with consumer capacity. |
Conclusion
Tuning max.poll.records provides a lever to control Kafka consumer performance, influencing both throughput and processing latency. Correct settings ensure effective consumption without overwhelming the consumer or risking stability through missed heartbeat signals. Thus, thoughtful adjustment of this parameter, in harmony with other consumer configurations, is essential for optimizing Kafka deployments.
Related reading
- How does one Kafka consumer read from more than one partition?
- How does RabbitMQ actually store the message physically?
- How does RabbitMQ compare to Mule
- How does rabbitmq heartbeat work
- How does RabbitMQ send messages to consumers?
- How does RD_KAFKA_PARTITION_UA work in librdkafka?
- How does (should) Kafka Consumer cope with Poison Messages
- How does Spring Kafka BATCH ack mode work with non-batch listener?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.