Scrivio Interview library
LeadershipPrincipal5 min read · updated 13 November 2026

Product wants end-to-end event latency below 20 ms at p99 for a new real-time feature, while finance wants Kafka cluster costs cut by 30 percent this year.

Client batching and compression settings sit in the middle of this conflict. How do you frame and settle the trade-off?

I would frame it as one mechanism with two prices: larger batches and compression cut requests, CPU, network and storage, but every millisecond of linger adds latency. Since only a small share of flows truly need p99 below 20 ms, I would create a latency class with tuned settings and, if needed, dedicated capacity for those flows, batch everything else aggressively, put measured cost-per-MB numbers on each option, make the latency class a visible choice with showback per team, and review agreed SLOs against measured latency and spend.

Why this question is asked

Conflicts between product speed and infrastructure cost usually end in a meeting where each side repeats its target. A senior engineer's job is to show that the two targets meet in a few specific settings, and that most of the conflict disappears once we stop treating all traffic the same. Interviewers ask this to see whether we can explain a technical mechanism in business terms and turn it into a decision with numbers. In this answer, we will recap the mechanism, segment the workloads, put numbers on the options, make the latency choice visible, and agree on how to keep it honest.

1A Quick Recap of the Mechanism, in Business Terms

A Kafka producer groups records into batches before sending. It waits up to linger.ms for more records to join a batch, then sends it. Bigger batches mean fewer requests for the brokers to handle, which saves broker CPU, and they compress better, which saves network, cross-zone transfer charges and disk. These are exactly the items that make up most of a Kafka bill.

The cost of waiting is latency: a record may sit in the producer for up to linger.ms before it leaves. With linger.ms=50, the fleet can be much cheaper to run, but no record on that path can reach a consumer in under 20 ms. With linger.ms=0 or 1, latency is lowest, but the cluster needs more CPU and network for the same data. So the two goals pull on the same lever.

The same lever, two prices (illustrative)
linger.msRecords per requestRelative broker CPUAdded latency
0 to 11 to 2100%~0 ms
5 (Kafka 4.0 default)3 to 10~60%up to 5 ms
2020 to 60~35%up to 20 ms
50 + zstd50 to 150~25%up to 50 ms
Shape only; real numbers come from a load test with our own traffic.

2Segment the Workloads

The product requirement is for one new real-time feature. In most companies, only a small share of flows, often well under a fifth of bytes, really need end-to-end p99 in the tens of milliseconds: user-facing notifications, fraud checks, live pricing. Logs, analytics, CDC and most domain events are consumed by systems that are happy with a second.

So instead of one setting for everything, we define two classes. The latency class gets low linger (a few milliseconds), lz4 compression, and if needed dedicated topics or a dedicated small cluster so its p99 is not hurt by heavy batch traffic. The default class, everything else, gets aggressive batching: linger.ms of 20 to 50, larger batches, zstd. The default class is where the 30 percent saving comes from, and the latency class is where the 20 ms promise is kept.

3Put Numbers on Each Option

Leaders should choose between numbers, not opinions. We run a load test with real data at several settings, measuring broker CPU, network, storage after compression and end-to-end latency, and convert them into cost per MB moved. Then we apply the results to the actual traffic mix.

Java
Load test results (example, per 100 MB/s of real traffic)
setting brokers needed cross-zone GB/day p99 end-to-end
linger 1, lz4 6 5,200 9 ms
linger 5, lz4 5 4,300 14 ms
linger 20, zstd 4 2,900 31 ms
linger 50, zstd 3 2,600 62 ms
Plan: latency class (10% of bytes) at linger 1-5; default class (90%) at linger 20-50
-> estimated cost reduction ~30%, latency class p99 within 20 ms

With numbers like these, the decision becomes clear: the saving comes mostly from the large default class, and the latency class costs a little more per MB but is small. If the numbers do not reach 30 percent, we know early and can look for other savings, such as tiered storage or follower fetching, rather than squeezing the latency flows.

4Make the Latency Class a Visible Choice

If the latency class is free, every team will ask for it. So we make it an explicit choice with a cost attached: a team requests the class for a topic, states the latency need and the user impact, and its cost per MB is shown back to the team in a monthly report (showback), even if no money moves between budgets. That keeps the class small and justified without a central team having to judge each request.

5Agree on SLOs and Review Them

We write down the agreed service level objectives: p99 end-to-end latency for each class, and a cost target per MB for the platform. We publish dashboards for both and review them on a regular cadence, quarterly for example, with product and finance in the room. When a new feature needs the latency class, it goes through the same process. When the cost target is missed, we look first at the default class's settings and at flows that moved into the latency class without real need.

6Follow-up questions

What if product insists that every event must be low latency?

I would ask which user-visible behaviour depends on each flow's latency, and show the cost of putting everything in the latency class from the load test. Usually most flows have no user waiting on them, and the conversation moves to the few that do. If the business still chooses low latency everywhere, that is a legitimate decision, but finance should see its cost.

Is linger.ms the only lever?

No, but it is the biggest on the client side. Compression codec, batch.size, partition counts, acks settings and consumer fetch settings also matter, and on the platform side tiered storage, follower fetching and right-sized brokers reduce cost without touching latency for the hot path.

7Conclusion

In this answer, we framed the conflict as one mechanism with two prices: batching and compression lower cost, and linger adds latency. We segmented flows into a small latency class with tuned settings and possibly dedicated capacity and a large default class with aggressive batching, measured cost per MB and latency at several settings with real data, made the latency class an explicit, visible choice with showback, and agreed on SLOs for both latency and cost that are reviewed regularly.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by explaining the mechanism in plain terms, because both sides are pulling on the same lever. Producers wait up to linger.ms to fill batches. Bigger batches mean fewer requests and better compression, so less broker CPU, less network and cross-zone transfer, less disk, which is most of the Kafka bill.

Then, if they want more

But a record can wait that long before it leaves, so latency goes up. Then I'd point out that the 20 ms requirement is for one feature, not for every event. Most flows, logs, analytics, CDC, internal domain events, are fine with a second. So I'd propose two classes.

A latency class with low linger, lz4, and if needed dedicated topics or a small dedicated cluster so it keeps its p99. And a default class with linger of 20 to 50 ms, bigger batches and zstd, which is where the cost saving comes from.

Next I'd put numbers on it: a load test with real data at several settings, giving brokers needed, cross-zone GB and p99 latency, applied to our actual traffic mix, so we can show whether 30 percent is reachable. To keep the latency class small, teams opt in with a stated need and see its cost in a monthly showback report.

Finally, we agree SLOs for both latency per class and cost per MB, and review them with product and finance every quarter.

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 "Client batching and compression settings sit in the middle of this conflict. How do you...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/1e12a21361/