Kafka Consumer
max.poll.records
Configuration Optimization
Data Streaming
Distributed Systems

Kafka max.poll.records: what reducing it does (default 500)

Codemia Knowledge Hub ·

max.poll.records caps how many records one poll() call returns, and its default is 500. Lowering it makes each poll loop shorter, so the consumer commits more often and responds faster to rebalances, at the cost of throughput. It is the main lever for avoiding max.poll.interval.ms timeouts when per-record processing is slow, but tune it together with max.poll.interval.ms, fetch.min.bytes and fetch.max.wait.ms.

What max.poll.records controls

Each poll() returns at most max.poll.records records from the client's internal prefetch buffer. It does not control how much data is fetched from the broker per network request (that is fetch.max.bytes and max.partition.fetch.bytes). Data is still prefetched in larger batches and buffered in memory. The setting only limits how many records reach your code per poll().

java
1Properties props = new Properties();
2props.put("bootstrap.servers", "broker1:9092,broker2:9092");
3props.put("group.id", "order-processor");
4props.put("max.poll.records", "50");  // Reduced from default 500
5props.put("max.poll.interval.ms", "300000");
6props.put("enable.auto.commit", "false");
7props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
8props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
9
10KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
11consumer.subscribe(Collections.singletonList("orders"));
12
13while (true) {
14    ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));
15    for (ConsumerRecord<String, String> record : records) {
16        processOrder(record);  // Slow: 50-200ms per record
17    }
18    consumer.commitSync();
19}

With max.poll.records=50 and 200ms per record, the worst case per poll() is 10 seconds. With the default of 500 it would be 100 seconds. That still fits within the default max.poll.interval.ms of 300,000ms (5 minutes), but at 1,000ms per record (as in the sizing example below) 500 records would take 500 seconds, exceed the limit and trigger a rebalance.

What changes when you reduce it

Shorter poll loop cycles

Smaller batches mean each loop finishes sooner and the consumer calls poll() more often, so the group coordinator keeps treating it as alive.

text
1Default (500 records, 100ms each):
2  poll() -> process 500 records -> 50 seconds -> commit -> poll()
3  
4Reduced (50 records, 100ms each):
5  poll() -> process 50 records -> 5 seconds -> commit -> poll()

More frequent commits

If you commit after each poll() cycle (the common pattern), commits happen more often, so less data is reprocessed after a crash.

java
1// With max.poll.records=50, this commits every 50 records
2// With max.poll.records=500, this commits every 500 records
3while (true) {
4    ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));
5    for (ConsumerRecord<String, String> record : records) {
6        process(record);
7    }
8    consumer.commitSync();  // Commit frequency tied to batch size
9}

Lower throughput

Each poll() has fixed overhead: the network round-trip, deserialization setup and coordinator communication. Smaller batches spread that cost over fewer records. More frequent polls also mean more coordinator traffic, more commit requests and more broker-side work, so the change is not free.

Faster rebalances

During a rebalance, a consumer must finish processing its current poll() batch before it can take part. A smaller batch finishes sooner, which shortens the pause for the whole consumer group.

Trade-offs at a glance

MetricHigher max.poll.recordsLower max.poll.records
ThroughputHigher (better amortization)Lower (more overhead per record)
Latency per batchHigherLower
Rebalance responsivenessSlowerFaster
Commit frequencyLess frequentMore frequent
Reprocessing after crashMore records replayedFewer records replayed
Risk of poll timeoutHigherLower
Network overhead ratioLowerHigher

Do not set it very low (for example 1) "for safety". Every record then pays the full overhead of a poll() cycle and throughput collapses.

Settings that interact with it

java
1// How long the coordinator waits for a poll() before kicking the consumer
2props.put("max.poll.interval.ms", "300000");  // 5 minutes
3
4// Minimum data the broker accumulates before responding to a fetch
5props.put("fetch.min.bytes", "1");  // Default: 1 byte (respond immediately)
6
7// Maximum time the broker waits to accumulate fetch.min.bytes
8props.put("fetch.max.wait.ms", "500");  // Default: 500ms
9
10// Maximum data per partition per fetch request
11props.put("max.partition.fetch.bytes", "1048576");  // Default: 1MB
12
13// Maximum data per fetch request across all partitions
14props.put("fetch.max.bytes", "52428800");  // Default: 50MB

A common mistake is lowering max.poll.records without adjusting fetch.min.bytes. If the broker waits to accumulate 1MB before responding but you only process 50 records per poll, the prefetch buffer fills and the excess sits in memory for later poll() calls. Memory pressure goes up without any gain in responsiveness.

How the fetch and poll settings fit together

text
1Broker                          Consumer JVM
2  |                               |
3  |  fetch request                |
4  |<------------------------------|  max.partition.fetch.bytes
5  |                               |  fetch.max.bytes
6  |  fetch response (N records)   |
7  |------------------------------>|
8  |                               |  [prefetch buffer]
9  |                               |     |
10  |                               |     | poll()
11  |                               |     | max.poll.records = M
12  |                               |     |
13  |                               |  [application gets min(N, M) records]
14  |                               |
15  |                               |  process + commit
16  |                               |  (must complete within max.poll.interval.ms)

Sizing max.poll.records

Measure worst-case per-record processing time first, then estimate:

text
1max.poll.records = max.poll.interval.ms / worst_case_processing_time_per_record
2
3Example:
4  max.poll.interval.ms = 300,000 ms (5 minutes)
5  worst_case_processing_time = 200 ms per record
6  Safety factor = 2x
7
8  max.poll.records = 300,000 / 200 / 2 = 750
9
10  Since default is 500, the default is fine in this case.
11  But if processing takes 1000ms per record:
12  max.poll.records = 300,000 / 1000 / 2 = 150

The safety factor covers GC pauses, network latency spikes and slow downstream services. 2x is a reasonable starting point.

If processing is simply too slow, lowering max.poll.records treats the symptom. Also consider async processing, a larger max.poll.interval.ms, or moving heavy work to a separate thread pool.

Spring Kafka configuration

In Spring Boot, set it in application properties:

yaml
1spring:
2  kafka:
3    consumer:
4      max-poll-records: 100
5      properties:
6        max.poll.interval.ms: 300000
7        fetch.min.bytes: 1

Or programmatically in the consumer factory:

java
1@Bean
2public ConsumerFactory<String, String> consumerFactory() {
3    Map<String, Object> props = new HashMap<>();
4    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "broker1:9092");
5    props.put(ConsumerConfig.GROUP_ID_CONFIG, "order-processor");
6    props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 100);
7    props.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, 300000);
8    return new DefaultKafkaConsumerFactory<>(props);
9}

Metrics to watch after the change

  • consumer_lag: should stay stable or fall. Rising lag means throughput dropped too far.
  • records-consumed-rate: total records per second. Expect a small decrease.
  • poll-rate: poll() calls per second. Should rise proportionally.
  • commit-rate: should rise, confirming more frequent commits.
  • rebalance count: should fall if poll timeouts were causing rebalances.
bash
# Check consumer lag with kafka-consumer-groups
kafka-consumer-groups.sh --bootstrap-server broker1:9092 \
  --group order-processor --describe

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design