conduktor.io ↗

Kafka Fetch Request Wire Format v7 — Binary Protocol Layout

What is Fetch?

Consumers and follower replicas both issue this continuously for log replication and consumption. When a consumer's fetch stalls with empty responses despite records existing, check isolation.level: read_committed consumers are blocked by open transactions until EndTxn.

Related Errors

FENCED_LEADER_EPOCH · FETCH_SESSION_ID_NOT_FOUND · FETCH_SESSION_TOPIC_ID_ERROR · INVALID_FETCH_SESSION_EPOCH · KAFKA_STORAGE_ERROR · LEADER_NOT_AVAILABLE · NETWORK_EXCEPTION · NOT_LEADER_OR_FOLLOWER · OFFSET_MOVED_TO_TIERED_STORAGE · OFFSET_NOT_AVAILABLE · OFFSET_OUT_OF_RANGE · THROTTLING_QUOTA_EXCEEDED · TOPIC_AUTHORIZATION_FAILED · UNKNOWN_LEADER_EPOCH · UNKNOWN_TOPIC_ID · UNKNOWN_TOPIC_OR_PARTITION

Wire Diagram

Request Header
message_size int32 · 4B
api_key int16 · 2B
api_version int16 · 2B
correlation_id int32 · 4B
client_id string
FetchRequest v7
ReplicaId int32 · 4B
MaxWaitMs int32 · 4B
MinBytes int32 · 4B
MaxBytes int32 · 4B
IsolationLevel int8 · 1B
SessionId int32 · 4B
SessionEpoch int32 · 4B
Topics array
ForgottenTopicsData array
Topic string
Partitions array
Partition int32 · 4B
FetchOffset int64 · 8B
LogStartOffset int64 · 8B
PartitionMaxBytes int32 · 4B
Topic string
Partitions []int32

Schema & Example

Schema
{
  "ReplicaId": int32,
  "MaxWaitMs": int32,
  "MinBytes": int32,
  "MaxBytes": int32,
  "IsolationLevel": int8,
  "SessionId": int32,
  "SessionEpoch": int32,
  "Topics": [{
      "Topic": string,
      "Partitions": [{
          "Partition": int32,
          "FetchOffset": int64,
          "LogStartOffset": int64,
          "PartitionMaxBytes": int32
      }]
  }],
  "ForgottenTopicsData": [{
      "Topic": string,
      "Partitions": [int32]
  }]
}
Example
{
  "ReplicaId": -1,
  "MaxWaitMs": 500,
  "MinBytes": 65536,
  "MaxBytes": 65536,
  "IsolationLevel": 1,
  "SessionId": 1847,
  "SessionEpoch": 12,
  "Topics": [{
      "Topic": "orders",
      "Partitions": [{
          "Partition": 0,
          "FetchOffset": 150382,
          "LogStartOffset": 284729,
          "PartitionMaxBytes": 65536
      }]
  }],
  "ForgottenTopicsData": [{
      "Topic": "orders",
      "Partitions": [1, 2, 3]
  }]
}