Quick revision
The short answer
When the bill grows much faster than produced bytes, the cause is usually in the other dimensions: storage from long retention and uncompressed JSON, data transfer from new consumer groups, replays and consumers in other zones or regions, per-partition charges from abandoned and over-partitioned topics, and capacity sized for bursty batch jobs. We break the bill down by dimension and by topic and team, then fix each: compress with zstd or lz4, trim retention, remove idle groups and use follower fetching, delete or shrink topics, schedule replays and add quotas, and finally right-size capacity. Per-team cost reports and checks in the provisioning pipeline keep the savings.
What to remember
In this answer, we saw that a bill doubling while production grew 20 percent points to the other dimensions. Storage grows with retention and uncompressed JSON, which producer compression with zstd or lz4 and sensible retention fix. Data transfer grows with consumer fan-out, replays and cross-zone or cross-region reads, which removing idle groups, follower fetching and moving consumers fix. Partition charges punish abandoned and over-partitioned topics. Capacity is set by peaks, so scheduling replays, quotas and right-sizing help. Per-team cost reports and checks in the provisioning pipeline keep it from coming back.
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.
When the bill grows much faster than produced bytes, the cause is usually in the other dimensions: storage from long retention and uncompressed JSON, data transfer from new consumer groups, replays and consumers in other zones or regions, per-partition charges from abandoned and over-partitioned topics, and capacity sized for bursty batch jobs. We break the bill down by dimension and by topic and team, then fix each: compress with zstd or lz4, trim retention, remove idle groups and use follower fetching, delete or shrink topics, schedule replays and add quotas, and finally right-size capacity. Per-team cost reports and checks in the provisioning pipeline keep the savings.
Why this question is asked
Cost questions are now a normal part of senior engineering interviews, because cloud bills are an engineering outcome. This scenario is a good test because the obvious explanation, more traffic, has been ruled out: production grew 20 percent, and the bill grew 100 percent. Interviewers want to see a methodical investigation rather than guesses. In this answer, we will first set up the investigation, then go through storage, data transfer, partitions and capacity units one by one with the usual causes and fixes, and end with how to make the savings stick.
1Setting Up the Investigation
We start with the bill itself, split by its four dimensions over the six months. If storage tripled while capacity units stayed flat, we know where to look. Then we need attribution: the service's metrics per topic, bytes in, bytes out, retained bytes and partition count, and per consumer group, bytes fetched and the client's network location. Joining these with a list of topic and group owners turns a single number into a table of who uses what.
Notice why produced bytes can mislead. Produced bytes drive only part of the bill. Storage depends on produced bytes times retention. Data transfer depends on how many times each byte is read and from where. Partition charges depend on how many partitions exist, used or not. Capacity units depend on peak throughput, not on the average.
| Bill line | Usual cause | First fix |
|---|---|---|
| Storage | Long retention, uncompressed JSON | zstd or lz4 compression, trim retention |
| Data transfer | New groups, replays, cross-zone reads | Remove idle groups, follower fetching |
| Partitions | Abandoned and over-partitioned topics | Delete or rebuild smaller |
| Capacity units | Bursty batch jobs set the peak | Schedule replays, add quotas, right-size |
2Storage: Retention and Compression
Storage cost is retained bytes, often counted per replica. We list topics by retained bytes and compare each topic's retention with what its consumers need. A common finding is a high-volume topic whose retention was set to 30 days during an investigation and never lowered, when consumers only need 3 days; that is a tenfold storage difference for one topic.
The other common finding is uncompressed JSON. Kafka compresses batches on the producer, and JSON with repeated field names compresses very well, often four to eight times. A producer without compression.type set sends and stores raw bytes. Enabling compression on the producers of the big topics lowers storage, data transfer and the throughput that capacity units are sized by, all at once.
The linger.ms and batch.size settings matter because compression works per batch: a batch of five records barely compresses, while a batch of five hundred does. The CPU cost on producers and consumers is usually small compared with the savings.
3Data Transfer: Fan-Out and Where Consumers Run
Data transfer grows with reads, and reads can grow without any change in production. Each new consumer group reads every byte of its topics again. A reprocessing job that replays 30 days reads a month of data in a few hours. So we list consumer groups by bytes fetched over time and look for new groups, groups that replay regularly, duplicate groups, two deployments of the same service with different group ids, and idle groups that still exist and still fetch.
Then we look at location. If the service bills cross-zone or cross-region traffic, a consumer in zone b reading from a leader in zone a pays for every byte. Follower fetching, where the consumer sets client.rack to its zone and the brokers allow it to read from a replica in that zone, removes most of that cost when the service supports it. Consumers running in another region or outside the provider pay egress, and moving them, or mirroring the needed topics closer to them, can be the single largest saving.
4Partitions: Abandoned and Over-Partitioned Topics
Per-partition pricing charges for partitions whether they carry traffic or not. We find topics with no produced bytes for 30 days and confirm with their owners that nothing needs them; many will be leftovers of experiments, migrations or deleted services. Deleting them is pure saving.
We also find topics with far more partitions than their throughput needs. A topic carrying 200 KB/s does not need 120 partitions; 6 or 12 give plenty of consumer parallelism. Kafka cannot reduce a topic's partition count, so shrinking means creating a smaller topic, moving producers and consumers to it, and deleting the old one, which is worth doing for the largest offenders.
5Capacity Units: What Sets the Peak
Capacity units are sized by the busiest period, not the average. If a nightly batch job replays a topic at 300 MB/s for an hour, that hour sets the capacity for the whole day. We plot throughput over a week and find what creates the peaks. Then we spread or schedule replays, add client quotas so a single batch job cannot burst without limit, and, once compression has lowered the throughput, reduce the capacity units to the new peak plus headroom.
6Making the Savings Stick
Costs crept up because nobody saw them. So we publish a monthly cost report per team, attributing storage, partitions and transfer to the owners of topics and consumer groups. Every topic and group gets a named owner, and anything without one is reviewed for deletion.
Then we move the checks into the provisioning pipeline, where topics are created: a maximum retention by default with an exception process, a partition count justified by expected throughput, compression required for producers of large topics, and an alert when a topic or group sees no traffic for 30 days. The goal is that the next doubling is caught in a pull request, not in a bill.
7Follow-up questions
How can we tell whether compression is actually on?
Look at the topic's bytes in versus the size of the records the application produces, or inspect a segment with kafka-dump-log.sh, which prints each batch's compression codec. The producer metric compression-rate-avg also shows the ratio; a value close to 1.0 means records are effectively uncompressed.
Is it safe to delete a topic that has had no traffic for 30 days?
Usually, but not blindly. Some topics are written rarely, such as yearly reports, or are read by a compacted-state bootstrap. Confirm with the owner, check for consumer groups with committed offsets, and if in doubt archive the topic to object storage before deleting it.
8Conclusion
In this answer, we saw that a bill doubling while production grew 20 percent points to the other dimensions. Storage grows with retention and uncompressed JSON, which producer compression with zstd or lz4 and sensible retention fix. Data transfer grows with consumer fan-out, replays and cross-zone or cross-region reads, which removing idle groups, follower fetching and moving consumers fix. Partition charges punish abandoned and over-partitioned topics. Capacity is set by peaks, so scheduling replays, quotas and right-sizing help. Per-team cost reports and checks in the provisioning pipeline keep it from coming back.
Open with
Since produced bytes grew only 20 percent, I would look at the other drivers, one bill line at a time, with metrics per topic and per consumer group joined to owners.
Then, if they want more
For storage, I would compare retained bytes with what consumers need; long retention on high-volume topics and uncompressed JSON are the usual causes, and producer compression with zstd or lz4 often shrinks JSON several times, which also cuts transfer and throughput.
For data transfer, consumer fan-out matters more than production, so I would look for new consumer groups, replays and reprocessing jobs, duplicates and idle groups, and consumers in other zones or regions. Follower fetching with client.rack can remove cross-zone reads if the service supports it.
For partitions, I would find topics without traffic for 30 days and topics with far more partitions than their throughput needs, and delete them or rebuild them smaller, since partitions cannot be reduced in place. For capacity units, I would check whether bursty batch jobs set the peak, schedule replays, add quotas, and right-size after compression lowers throughput.
To make it stick, I would publish per-team cost reports, require an owner for every topic and group, and add retention and partition checks to the provisioning pipeline.
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 how you find the causes and which changes you would make.": https://scrivio-interview-library.netlify.app/spring-boot/kafka-operations/d62f865f0f/