# org.apache.kafka.common.errors.InvalidFetchSizeException: Fetch size 0 is invalid

- **ID:** `kafka/invalid-fetch-size`
- **Domain:** kafka
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Consumer or follower fetch request specified a fetch size of 0 bytes, which is not allowed by the broker protocol.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Kafka 3.4.0 | active | — | — |
| Kafka 3.5.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |

## Workarounds

1. **Set fetch.max.bytes to a positive value (e.g., 52428800) in consumer properties.
Example:
properties.put(ConsumerConfig.FETCH_MAX_BYTES_CONFIG, 52428800);
properties.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, 1048576);
# Also ensure fetch.min.bytes is > 0
properties.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, 1);** (80% success)
   ```
   Set fetch.max.bytes to a positive value (e.g., 52428800) in consumer properties.
Example:
properties.put(ConsumerConfig.FETCH_MAX_BYTES_CONFIG, 52428800);
properties.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, 1048576);
# Also ensure fetch.min.bytes is > 0
properties.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, 1);
   ```
2. **If using Kafka Streams, ensure 'fetch.max.bytes' is set in StreamsConfig.
Command to check current config:
kafka-consumer-groups --bootstrap-server localhost:9092 --group my-group --describe
# If fetch.max.bytes is 0, override in properties:
props.put(StreamsConfig.consumerPrefix(ConsumerConfig.FETCH_MAX_BYTES_CONFIG), 52428800);** (75% success)
   ```
   If using Kafka Streams, ensure 'fetch.max.bytes' is set in StreamsConfig.
Command to check current config:
kafka-consumer-groups --bootstrap-server localhost:9092 --group my-group --describe
# If fetch.max.bytes is 0, override in properties:
props.put(StreamsConfig.consumerPrefix(ConsumerConfig.FETCH_MAX_BYTES_CONFIG), 52428800);
   ```

## Dead Ends

- **Set fetch.min.bytes to 1 instead of 0** — fetch.min.bytes controls minimum bytes before returning data, not the fetch size itself; setting to 1 may cause unnecessary polling. (50% fail)
- **Disable fetch.max.bytes in consumer config** — Removing the config may default to 0 in some clients, causing the same error. (70% fail)
- **Upgrade Kafka client to latest version** — The issue is often a misconfigured client, not a bug; upgrading may not fix if config is wrong. (40% fail)
