November 3, 2026
From 42% to 2.5% CPU: How We Optimized Our Kafka Cluster and Cut Its Cost by 83%
Author: Yannis Gonianakis (Staff Software Engineer), Alexey Seleznev (Data Engineer), Riccardo Bassetto (Data Engineer), Vlad Evrasenkov (Engineering Manager, Data Engineering)
Miro's Data Engineering team was about to expand one of its oldest Amazon MSK clusters, but first audited how it was used. Fixing inefficient Kafka client settings and a compression mismatch cut CPU utilization by about 94%, and downscaling and then replacing the cluster cut infrastructure costs by about 83%.
At Miro, we use Apache Kafka for asynchronous service integrations, logging infrastructure, and our near-real-time Data Analytics platform. We operate multiple Kafka clusters, and we separate workloads based on their load profile and business needs.
In this post, we share how the Data Engineering team optimized one of our oldest Amazon MSK (Managed Streaming for Apache Kafka) clusters, cutting CPU utilization by ~94% (from 42% to 2.5%) and delivering an ~83% reduction in infrastructure costs, while also creating more capacity headroom through performance optimizations and strong team collaboration.

Context
The analytics event tracking system has been running in production at Miro since 2017. In 2023, we migrated parts of the infrastructure to Kubernetes.
The high-level architecture consists of:
- a Spring Boot API service, called EventHub, running on Kubernetes
- an MSK Kafka cluster
- a set of Apache Flink jobs performing event ingestion and validation
A simplified view of the analytics pipeline is shown in the diagram below:

As shown in the diagram, EventHub is sending all events to the analytics-events-raw topic, where a Flink job will perform validation and split the events into two other topics: analytics-events-valid and analytics-events-invalid.
By the end of 2024, the system was running smoothly, processing approximately 5-6 billion events per day, while the cluster was around 42% CPU utilization at peak.
However, as we were approaching the provisioned storage capacity, we knew that soon we’d have to expand the cluster with extra storage and processing power, which would have driven costs even higher.
At that point, instead of expanding the cluster, the team decided to take a step back and audit the cluster’s usage. We examined the topics with the highest data volumes, and noticed something unusual: the output topic analytics-events-valid was receiving more bytes per second than the source topic analytics-events-raw.

This was a clear indication that the Kafka producers in EventHub and the Flink jobs were using different compression algorithms. Indeed, EventHub was using gzip while Flink was using snappy. While gzip has a better compression ratio, it is generally not recommended due to high overhead.
We decided to go a step further and take a closer look at the client configuration of each producer. We quickly discovered many other inefficiencies.
What was wrong?
Both Apache Flink and Spring Boot use the Apache Kafka Java Client, which is a foundational and highly configurable library. However, as expected, the default settings are often not optimal for certain applications.
For our analytics events workload, we care more about high throughput, i.e. moving as much data as possible within a given time, than about high durability or low latency.
The default linger.ms=0 causes messages to be sent as soon as they appear. Producers will not wait for their buffers to fill up, leading to inefficient batching, ineffective compression and a high number of small requests.
Indeed, when looking at our cluster metrics, at peak traffic, the cluster was receiving nearly 190K requests and 500 MB of incoming data per second, driving up CPU usage, network traffic and storage costs.
Choosing a compression algorithm
Our events are in JSON format and relatively small. Kafka supports different compression algorithms and we benchmarked different algorithms by publishing a number of analytics events to a single-node Kafka cluster and inspecting the size of data occupied by the topic.

For our workload, zstd gave a better compression ratio than gzip at a higher throughput, and a much better ratio than snappy and lz4 at a similar throughput.
Optimizing batching configuration
With such small events, we would benefit from increasing the batch.size and linger.ms settings, to allow enough time for messages to buffer. Given that there is no clear answer as to which settings would work best, our team ran several benchmarks in our dedicated performance testing environment and evaluated the results.
Once we were happy with the preliminary results, we updated EventHub using the following configuration:
- linger.ms: 250ms (default: 0; 5ms since Kafka 4.0) - The amount of time the producer waits before sending a batch of records. Increasing this allows more records to be batched together, improving throughput at the cost of higher latency. For our use case, higher latency is acceptable in exchange for better batching efficiency.
- batch.size: 256 KiB (default: 16 KiB) - The maximum size of a batch of records sent to a single partition. Larger batches reduce request overhead and broker load, but require more memory. This is especially beneficial when producing high volumes of small messages.
- buffer.memory: 256 MiB (default: 32 MiB) - The total memory available to the producer for buffering unsent records. If the buffer fills up, send() calls will block or fail. A larger buffer supports larger batches and prevents the producer from blocking when message production temporarily outpaces network or broker capacity.
- compression.type: zstd (default: none; EventHub used gzip) - The compression algorithm used for record batches (e.g., gzip, snappy, lz4, zstd). Compression reduces network usage and disk I/O, often improving throughput with minimal CPU overhead. Zstandard offers an excellent balance between compression ratio and CPU usage, making it well-suited for high-throughput workloads.
- acks: 1 (default: all) - Controls the durability guarantees for produced records. With acks=all, the producer waits for all in-sync replicas to acknowledge the write. With acks=1, it waits only for the leader, which allows for higher throughput and lower latency. The trade-off is weaker durability: a record can be lost if the leader fails before the data is replicated. This is acceptable for our analytics events, but it may not be for your workload.
Impact
Once we deployed these changes to production, we saw large performance gains for EventHub and our analytics Kafka cluster.
Impact on Producer (EventHub) performance
On the producer side, EventHub CPU utilization dropped by 33% and data send rate decreased by 62%. These changes show the combined effect of larger batches and zstd compression.

At the same time, the request rate dropped from 15K req/sec to merely 200 req/sec, at peak, and the average batch size per request increased, which shows that we are able to move more compressed data per request to Kafka.

On the other hand, per-message latency increased, because messages now spend more time in the queue before being sent. This is not a problem for our case. At the same time, the average request latency to the cluster dropped by more than two-thirds (67%), because the cluster is less loaded and we reduced the number of expected broker acknowledgements. This is important, because in case of a sudden spike in traffic, the requests can be dispatched quickly without blocking and saturating the producer service.
Impact on Kafka cluster performance
On the cluster side, the impact was also significant. The CPU usage of the cluster dropped from 40% to 15% and requests per second almost halved. The amount of data flowing into the cluster also dropped below 350 MB per second while the number of messages per second remained the same, meaning we were able to move the same amount of data, more efficiently.

Scaling our learnings
After this point, we knew there was further room for optimization, so we systematically applied the learnings from EventHub across all our deployed Apache Flink jobs (and later other production Kafka clients). In the Flink jobs, we switched the Kafka sink from snappy to zstd and tuned batching in the same way. We kept acks=all there, because our validation job writes with exactly-once guarantees, which rely on Kafka transactions. You can see the effect as the second drop in the CPU chart at the top of this post. As a result, the load profile of the cluster today is very different from what it used to be. For the same amount of input records, we only use a small fraction of the cluster capacity, presenting an opportunity for downscaling the cluster and saving on infrastructure costs.
- Ingest volume: ~80% reduction (500 MB/s → ~90 MB/s)
- CPU utilization: ~94% reduction (42% → 2.5%)
- VPC traffic MSK → Databricks: ~70% reduction (1.4 Gib/s → 400 Mib/s)

Replacing our Kafka infrastructure
The new usage profile of the cluster gave us a chance to cut costs. However, while the team was able to quickly downscale compute resources (shoutout to Riccardo Bassetto), it was not possible to downscale storage without service disruption.
At the same time, our Kafka cluster was aging. Since its initial deployment in 2017, the Kafka ecosystem has evolved significantly. Two main advances are the ability to run Kafka without ZooKeeper (KRaft) and the usage of tiered storage (i.e. moving data to cold-storage for longer retention and lower costs).
The aging infrastructure and the inability to downscale storage of the old cluster made a clean migration to a modern Kafka 4.x deployment the best option for us. Alexey Seleznev led the plan and orchestrated a smooth migration. To do this, we switched the producers to the new cluster. Some consumers read from both clusters, and others moved to the new cluster once the old topics were drained.
Thanks to our combined efforts across our Kafka clusters, including cluster downscaling, improved compression, and the migration to a new cluster, we’ve reduced infrastructure costs by ~83% compared to the beginning of the year. The chart below shows the main steps. Downscaling compute, which the lower load made possible, together with retiring an obsolete development environment, delivered a little over half of the savings. Replacing the cluster delivered the rest: with ingest volume down by about 80%, we needed far less storage, and MSK cannot shrink storage in place.

The end result was a more modern Kafka deployment with lots of headroom for growth.
Closing thoughts
Instead of adding hardware, we audited our own topics and questioned client defaults, and that is where the savings came from. Measuring and tuning Kafka workloads is essential.
Benchmark performance in your own environment, and consider your event volumes, message sizes and throughput characteristics. Since Kafka 3.7, KIP-714 gives cluster operators a standard way to collect client-side metrics on the brokers.
Apache®, Apache Kafka®, Apache Flink®, Kafka, Flink, and the associated logos are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. No endorsement by the Apache Software Foundation is implied by the use of these marks. Amazon Web Services, AWS, and Amazon MSK are trademarks of Amazon.com, Inc. or its affiliates. Spring and Spring Boot are trademarks of Broadcom Inc. and/or its subsidiaries. Databricks and Snowflake are trademarks of their respective owners. All other trademarks are the property of their respective owners. Use of these names and logos is for identification purposes only and does not imply endorsement or affiliation.