liveBook · Manning

Fetch request

As explained in Apache Kafka in Action

A fetch request is a Kafka protocol request for retrieving records from a partition.

A fetch request lets a Kafka consumer retrieve records from a partition. It names the partition and the offset where the broker should begin returning messages. Consumers usually delegate partition and offset handling to the Kafka library; console consumers can specify them directly. section 9.1.1

A broker handles a fetch request through a read-oriented data flow:

  • Network threads receive the request and place it in the request queue. section 9.2
  • I/O threads read batches from the filesystem, although the page cache may satisfy the request without disk access. section 9.2
  • The request purgatory can wait for more messages instead of waiting for another broker. section 9.2
  • fetch.min.bytes controls the minimum available response size, while fetch.max.wait.ms limits how long the broker waits; defaults are 1 byte and 500 milliseconds. section 9.2
  • The response enters the response queue before a network thread sends it back to the consumer. section 9.2

Reading a partition from offset zero

A console consumer can request partition 0 from offset 0 with kafka-console-consumer.sh. The command reads records from products.prices.changelog, producing values such as “coffee pads 10,” “coffee pads 11,” and “coffee pads 12.” In ordinary consumers, the library selects the partition and offset. Consumers start at the latest messages by default; setting auto.offset.reset to earliest starts at the beginning when appropriate. section 9.1.1

Fetch requests also support replication: followers use a special fetch request to copy records from a partition leader and report their current offsets. This keeps them current and eligible to take over when a leader fails. section 5.3

How Apache Kafka in Action covers it

How deep it goes
Traces offsets, queues, I/O, page cache, request purgatory, response timing, and replication, without detailing protocol fields.
Examples
Demonstrates kafka-console-consumer.sh reading products.prices.changelog from partition 0 and offset 0, plus follower replication.
What it assumes
Assumes familiarity with Kafka consumers, brokers, partitions, leaders, and offsets while explaining their roles in fetching.
What you can do after
Apply it via Kafka consumers by choosing starting offsets and tuning fetch.min.bytes and fetch.max.wait.ms for performance.
How it connects
Connects consumers, partitions, offsets, brokers, filesystem reads, page cache, request purgatory, replication, and leader-follower architecture.

Also explained in

Compare how 2 books explain fetch request →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.