Quick revision
The short answer
Requests wait 900 ms in the request queue while the I/O handler threads are idle only 3 percent of the time, so the request handler pool is saturated; local work (20 ms) and waiting for replicas (40 ms) are fine, and network threads have spare capacity. We look for what is consuming handler time, usually a flood of small requests, expensive request types or a slow disk blocking threads, then fix client batching, add I/O threads in line with cores and disks, and protect the broker with request quotas.
What to remember
In this answer, we walked through the broker request pipeline: network threads read requests into a shared queue, I/O threads do the work, purgatory holds requests waiting for followers or data, and network threads send responses, with a time metric for each stage. The numbers show 900 ms in the request queue and I/O threads 97 percent busy, while local and remote times are fine, so the handler pool is saturated. We find the cause in request rates, slow disks or a profile, then fix client batching, size num.io.threads to cores and disks, and use request quotas.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Requests wait 900 ms in the request queue while the I/O handler threads are idle only 3 percent of the time, so the request handler pool is saturated; local work (20 ms) and waiting for replicas (40 ms) are fine, and network threads have spare capacity. We look for what is consuming handler time, usually a flood of small requests, expensive request types or a slow disk blocking threads, then fix client batching, add I/O threads in line with cores and disks, and protect the broker with request quotas.
Why this question is asked
Kafka brokers publish a detailed breakdown of where each request spends its time, and that breakdown turns a vague 'the broker is slow' into a precise diagnosis. Interviewers give these numbers to see whether we know the request pipeline well enough to read them. In this answer, we will walk through the broker's request pipeline stage by stage, map each metric to a stage, read the numbers in the question, look for the cause, and then go through the fixes.
1The Broker Request Pipeline
A broker handles requests with two thread pools and a queue between them. Network threads (num.network.threads, 3 by default) each own a set of client connections. They read bytes from sockets, turn them into request objects and put them in a single shared request queue, whose size is limited by queued.max.requests (500 by default). I/O threads, also called request handler threads (num.io.threads, 8 by default), take requests from that queue and do the work: validate and append a produce to the log, read data for a fetch, or answer a metadata request.
Some requests cannot be answered at once. A produce with acks=all must wait until followers have replicated it, and a fetch may wait until fetch.min.bytes of data is available. These are parked in purgatory, a waiting area that completes them later without holding an I/O thread. When the response is ready, it goes to a response queue for the network thread that owns the connection, which writes it to the socket.
- Network thread reads the request
num.network.threads;NetworkProcessorAvgIdlePercent - Request queue
RequestQueueTimeMs: waiting for a free I/O thread - I/O thread does the work
LocalTimeMs;RequestHandlerAvgIdlePercent - Purgatory
RemoteTimeMs: waiting for followers or more data - Response queue
ResponseQueueTimeMs - Network thread sends the response
ResponseSendTimeMs
6 layers, from the top down. Step through them one at a time.
2Reading the Numbers
Total produce p99 is 1.2 seconds. Of that, 900 ms is RequestQueueTimeMs: the request sat in the queue waiting for any I/O thread to pick it up. LocalTimeMs of 20 ms is the time an I/O thread spent working on it, and RemoteTimeMs of 40 ms is the wait for followers to replicate. The rest is in response queueing, sending and throttling.
RequestHandlerAvgIdlePercent of 0.03 means the I/O threads are idle 3 percent of the time, which is effectively saturated; a healthy broker usually shows well above 0.3. NetworkProcessorAvgIdlePercent of 0.6 means network threads are idle 60 percent of the time, so they are not the bottleneck. Notice that disk and replication are fine: if the disk were slow, LocalTimeMs would be high, and if followers were slow, RemoteTimeMs would be high. The requests are fast once they get a thread; they just cannot get one.
3Finding What Uses the Handler Time
Saturated handler threads mean either too many requests, or some requests that each take too long. We check request rates per request type (RequestsPerSec by request and version) and per client, looking for a jump. A common cause is a surge of tiny produce requests: producers with linger.ms=0, services calling flush() or get() after each send, or a new client fleet with many connections. Each request costs handler time no matter how small it is.
Other causes are expensive request types, such as many metadata requests from misbehaving clients or large fetches of old data, and one slow disk. If one log directory is on a failing disk, I/O threads that append to it block, the pool drains, and requests for healthy partitions queue behind them. The tell is a high LocalTimeMs for some partitions or a single disk with high await time in iostat. In our numbers the p99 LocalTimeMs is 20 ms, a little high for an append, so we would check disk latency too.
A thread dump or async-profiler run on the broker shows what the I/O threads are doing right now, which often settles the question in minutes.
4Fixing It
If the cause is tiny requests, the real fix is on the clients: raise linger.ms and batch.size so the same bytes arrive in fewer requests, and remove synchronous sends. That can cut the request rate several times. Meanwhile, we can add I/O threads. num.io.threads is a dynamic broker setting, so it can be changed without a restart. A common guide is around the number of cores, and at least as many as the data disks, because threads blocked on I/O are not using CPU.
Adding threads helps only if the CPU has headroom; if the broker is CPU-bound, more threads just share the same cores. Request quotas protect everyone else: request_percentage limits the share of handler and network thread time a client or user may use, and the broker throttles clients that exceed it. If a slow disk is the cause, we replace it or move its partitions, because no thread count fixes a disk that blocks every write.
5Follow-up questions
Why does the produce wait for followers not block an I/O thread?
Because the request is parked in purgatory once the leader has appended it. The I/O thread is released, and the request completes when followers fetch far enough to advance the high watermark. That is why RemoteTimeMs can be large without hurting handler idle time.
When would network threads be the bottleneck instead?
When NetworkProcessorAvgIdlePercent drops low, typically with many connections, TLS encryption on every byte, or very high request rates. Then requests take long to be read from sockets and responses wait in the response queue or take long to send. Increasing num.network.threads helps in that case.
6Conclusion
In this answer, we walked through the broker request pipeline: network threads read requests into a shared queue, I/O threads do the work, purgatory holds requests waiting for followers or data, and network threads send responses, with a time metric for each stage. The numbers show 900 ms in the request queue and I/O threads 97 percent busy, while local and remote times are fine, so the handler pool is saturated. We find the cause in request rates, slow disks or a profile, then fix client batching, size num.io.threads to cores and disks, and use request quotas.
Open with
I would start with the pipeline. Network threads, three by default, read requests from sockets and put them on one shared request queue. I/O threads, eight by default, take them off the queue and do the work, like appending a produce to the log.
Then, if they want more
If a request has to wait, like an acks=all produce waiting for followers, it is parked in purgatory so it doesn't hold a thread, and then the response goes back through the network thread. Each stage has a metric. Here, 900 of the 1,200 ms is RequestQueueTimeMs, waiting for a free I/O thread.
LocalTimeMs of 20 ms and RemoteTimeMs of 40 ms say that once a request gets a thread, the disk and replication are fine. RequestHandlerAvgIdlePercent of 0.03 means the I/O threads are 97 percent busy, while network threads are 60 percent idle. So the handler pool is saturated.
Next I find out what is using it: request rates per type and per client, looking for a flood of tiny produce requests from linger.ms zero or a flush after every send, expensive requests like constant metadata calls, or one slow disk blocking threads, which I would check with iostat and a thread dump.
Fixes: correct the client batching, which cuts the request rate a lot; raise num.io.threads dynamically if CPU has room, roughly in line with cores and disks; and set request_percentage quotas so one client can't take all the handler time again.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Walk through the broker request pipeline and explain what these numbers say and what you...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/11dbf8894d/