Quick revision
The short answer
At 1.3 records per request, brokers spend their CPU on per-request overhead rather than on data, and the same bytes in ten times fewer requests would cut that load sharply. We find the worst producers with per-client request rates and the batch-size-avg, records-per-request-avg and request-rate metrics, fix the usual causes (linger.ms=0 in old configurations, flush() or get() after every send, many low-traffic partitions) through shared configuration with reviewed exceptions for latency-sensitive services, and protect brokers with request quotas while tracking requests per MB across the fleet.
What to remember
In this answer, we saw that 1.3 records per request means brokers pay per-request overhead almost per record, so fewer, fuller requests cut CPU sharply. We found the worst producers through per-client broker metrics and producer metrics such as records-per-request-avg, batch-size-avg and record-queue-time-avg, traced the causes to linger.ms=0, synchronous sends and too many partitions, fixed them through shared configuration with reviewed exceptions, and protected brokers with request quotas while tracking requests per MB across the fleet.
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.
At 1.3 records per request, brokers spend their CPU on per-request overhead rather than on data, and the same bytes in ten times fewer requests would cut that load sharply. We find the worst producers with per-client request rates and the batch-size-avg, records-per-request-avg and request-rate metrics, fix the usual causes (linger.ms=0 in old configurations, flush() or get() after every send, many low-traffic partitions) through shared configuration with reviewed exceptions for latency-sensitive services, and protect brokers with request quotas while tracking requests per MB across the fleet.
Why this question is asked
A shared cluster that runs out of CPU usually triggers a request for more brokers. Before buying them, it is worth asking what the CPU is spent on, and on many clusters the answer is overhead: hundreds of thousands of requests that each carry almost nothing. Interviewers ask this to see whether we can diagnose a fleet-wide problem from metrics and fix it across many teams without breaking anyone's latency goals. In this answer, we will recap why tiny requests are expensive, find the producers responsible, look at the usual causes in code and configuration, roll out the fix safely, and protect the brokers while we do.
1A Quick Recap: Why Request Count Matters
Every Produce request has a fixed cost on the broker, independent of its size: a network thread reads and parses it, it waits in the request queue, an I/O thread validates it and appends each batch to its partition's log, the broker updates metrics and tracking for replication, and a response is built and sent. With acks=all, the request also waits in purgatory until followers catch up, and followers send their own fetches to copy it.
When a request carries hundreds of records, that fixed cost is spread thin. At 1.3 records per request, it is paid almost once per record. 400,000 requests per second carrying about 520,000 records could be carried in perhaps 40,000 requests with reasonable batching, and broker CPU falls roughly with the request count.
2Finding the Worst Producers
The broker shows the total; we need to know who sends the requests. Two sources help. On the broker side, per-client metrics from the quota system (request time and byte rate by user or client id) and connection counts by client software show which identities generate the most requests. On the client side, every Java producer exposes metrics we can collect centrally.
We rank services by request rate times their share of the cluster and look at the top twenty; in most fleets a small number of services cause most of the requests. A record-queue-time-avg near zero is a strong clue that batches are being pushed out immediately, either by linger.ms=0 or by code that forces sends.
3The Usual Causes
Old configurations are the first cause. Before Kafka 4.0, linger.ms defaulted to 0, and many services copied settings from old examples that set it explicitly to 0. The second cause is synchronous sends in code: calling get() on the Future after each send, or flush() after each record, forces every record out in its own request and also makes the application wait for each round trip.
- records-per-request-avg below 5?YesInvestigate this serviceNoFine, move to the next
- record-queue-time near 0?YesCheck linger.ms and flush/get callsNoLook at partition count
- Many partitions, little traffic each?YesFewer partitions or keyless sticky sendsNoRaise linger.ms and batch.size
- Latency-sensitive?YesReviewed exception with tuned settingsNoApply the shared defaults
4 steps in order. Play them, or step through them one at a time.
The third cause is partitioning. Each partition fills its own batch, so a topic with 200 partitions and 300 records per second gives every partition one or two records per second, and no realistic linger setting builds a real batch. Reducing partitions on low-traffic topics, which requires creating a new topic and migrating since partitions cannot be removed, makes batching possible again.
4Rolling Out the Fix Without Breaking Latency Goals
We fix it through shared configuration rather than asking 150 teams to tune their own settings. The company's client configuration or thin library sets linger.ms to 10 or 20 ms, a larger batch.size such as 64 KB, compression with lz4 or zstd, and idempotence on. Teams pick it up on their next deployment. A 10 to 20 ms linger adds at most that much to produce latency, which is well inside the goals of most event-driven services, and in practice batching often lowers p99 latency because the brokers are no longer overloaded.
Services with tight latency goals get an explicit exception: they can keep a low linger, but the choice is written down, reviewed and visible in the fleet report. We migrate the worst twenty services first, with their owners, and measure the broker CPU drop after each, which builds the case for the rest.
5Protecting the Brokers Meanwhile
While the fix rolls out, request quotas keep any one service from taking over. request_percentage limits the share of broker thread time a client or user may use per quota window, and the broker throttles clients that exceed it by delaying responses. We set a default quota for all users and higher ones for known large services.
Finally, we track an efficiency measure for the fleet, such as requests per MB produced, per service and in total. It turns batching from a one-off clean-up into a number that stays visible, so the problem does not quietly return with the next generation of services.
6Follow-up questions
Why not just add brokers?
It would work, at a cost, and the waste would remain. The same CPU spent on overhead would simply be spread across more machines. Fixing batching usually frees far more capacity than a few brokers add, and it also reduces network and disk work through better compression.
Can the broker force clients to batch?
Not directly. Quotas can throttle clients that use too much request time, which encourages fixes, but batching is a client-side decision. That is why shared defaults and visibility per team matter more than broker settings.
7Conclusion
In this answer, we saw that 1.3 records per request means brokers pay per-request overhead almost per record, so fewer, fuller requests cut CPU sharply. We found the worst producers through per-client broker metrics and producer metrics such as records-per-request-avg, batch-size-avg and record-queue-time-avg, traced the causes to linger.ms=0, synchronous sends and too many partitions, fixed them through shared configuration with reviewed exceptions, and protected brokers with request quotas while tracking requests per MB across the fleet.
Open with
The headline number is 1.3 records per request. Each Produce request has a fixed cost on the broker, network thread, queue, I/O thread, replication tracking, response, so at that ratio the brokers are spending CPU on overhead, not data.
Then, if they want more
The same 520,000 records a second in ten times fewer requests would cut broker CPU a lot. To diagnose it, I'd find who sends the requests: per-client request time from the quota metrics on the brokers, and producer metrics collected centrally, request-rate, records-per-request-avg, batch-size-avg, and record-queue-time-avg. Usually a few services cause most of it.
Record queue time near zero means batches go out immediately, and the usual causes are linger.ms set to 0 in old configs, it was the default before 4.0, code that calls get() or flush() after every send, and topics with lots of partitions and little traffic, where no linger can build a batch.
The fix goes through shared configuration, not 150 separate tuning efforts: linger.ms 10 to 20, a bigger batch.size, compression, idempotence. That adds at most 10 to 20 ms, and often p99 actually improves because the brokers stop being overloaded. Latency-sensitive services get a written, reviewed exception. I'd start with the worst twenty services and show the CPU drop.
Meanwhile I'd put request_percentage quotas in place so no one client can saturate the brokers, and track requests per MB per service so this doesn't creep back.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Kafka 4.0
- 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 "How do you diagnose this and fix it across the fleet without breaking teams' latency...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/0df16963e9/