Kafka performance best practices for monitoring and alerting
Sion Smith12 July 2023
Blogs7 mins read
Updated November 2026: We have restructured this guide with settings tables and updated it for Apache Kafka 4.x, including KRaft, the new consumer rebalance protocol and share groups.
Apache Kafka underpins real-time pipelines where missed SLOs show up as consumer lag, timeouts or rising cloud bills. From OSO’s work across enterprise Kafka estates, the teams that improve performance fastest treat tuning as a measured loop: take a baseline, change one lever, then measure again. Guessing at partition counts, acks or consumer numbers usually trades one bottleneck for another.
Why does Kafka performance tuning matter?
Every Kafka performance problem eventually reaches the business as late data, failed requests or a larger infrastructure bill. Tuning matters because the defaults are a reasonable starting point, not an answer for your workload. Message size, key distribution, durability requirements and downstream processing all change which setting is the real bottleneck.
This guide covers the practical Kafka performance best practices for topics, producers, consumers and monitoring, so you can move from “it feels slow” to a clear plan.
How should you tune topics and partitions for Kafka performance?
Partition count drives both parallelism and operational cost. More partitions generally raise throughput for producers and consumer groups, but each partition adds metadata, open files and rebalance work on brokers and clients.
Practical guidance:
Start from expected peak throughput and the consumer parallelism you need, not an arbitrary large number.
Prefer fewer, well-sized partitions over thousands of tiny ones that never fill a batch.
Watch under-replicated and offline partitions after any increase. Those signals often appear before end users notice latency.
Revisit your partition strategy when you adopt KRaft, tiered storage or multi-region topologies. ZooKeeper-era rules of thumb are rarely optimal.
Consumer lag is the headline Kafka performance metric for most reading workloads. Three levers dominate:
Parallelism. Scale the consumer group so every partition is actively read. In a classic consumer group, one consumer per partition is the ceiling, and extra consumers sit idle.
Commit strategy. Batch offset commits where your processing allows it. Committing every record increases broker traffic, while committing too rarely lengthens reprocessing after a failure.
Poll loop health. Check max.poll.records, fetch sizes and whether slow processing blocks the poll loop. A fast fetch with slow business logic still looks like “Kafka is slow”.
Kafka 4.0 made the new consumer rebalance protocol (KIP-848) generally available, which cuts the stop-the-world pauses that used to hurt large groups. Read more in our guide to the new consumer rebalance protocol. If you need more consumers than partitions for record-by-record work, share groups (KIP-932) are production-ready in Kafka 4.2: see Kafka queues via share groups.
How do you optimise Kafka producers without losing durability?
Producer tuning is where throughput and data integrity trade off most clearly:
Setting
What it controls
Performance guidance
acks
How many replicas must confirm a write
acks=all with a suitable min.insync.replicas favours durability; weaker acks cut latency but widen the failure window
batch.size
Maximum bytes per partition batch
Larger batches improve throughput and compression for small messages
linger.ms
How long the client waits to fill a batch
A few milliseconds often helps throughput; measure p99 latency before and after
buffer.memory
Memory for records waiting to be sent
Must absorb bursts; when full, send() blocks, which shows up as application latency
compression.type
Codec applied to each batch
lz4 or zstd usually reduce network and disk use for a small CPU cost
Since Kafka 3.0 the producer defaults to acks=all with idempotence enabled, but many estates still run older clients or explicit overrides, so confirm what your producers actually send. Change one setting at a time and measure end-to-end latency under a realistic produce rate. The official reference is the Kafka producer configs documentation, and our Kafka producer best practices guide goes deeper.
What trade-offs should you weigh when improving Kafka performance?
Every Kafka performance change sits on four axes: throughput, latency, data integrity and cost. Raising partitions or brokers can lift throughput while increasing management overhead and cloud spend. Weakening acknowledgements can cut publish latency while widening the failure window.
Before you scale out:
Find out whether the bottleneck is the client, the broker, disk, network or downstream processing.
Fix hot partitions, slow consumers or badly sized batches before adding hardware.
Budget for the operational cost of more brokers, more partitions and more alerts.
If you are also cutting platform spend, OSO’s fully managed Kafka and Kafka services engagements often combine performance tuning with right-sizing, so cost and SLOs move together.
What should you monitor to keep Kafka performance stable?
Automation matters once a cluster is larger than a handful of brokers. Manual checks don’t keep up with partition churn and consumer group changes.
Metric
Why it matters
Alert when
Active controller count
Shows the cluster has exactly one active controller (in KRaft, one per controller quorum)
It is not exactly one for more than a short election
Under-replicated partitions
Followers falling behind put durability at risk
Above zero for several minutes
Offline partitions
Partitions with no leader can’t be read or written
Above zero
Consumer lag
Shows whether consumers keep up, by group and partition
Lag grows steadily rather than recovering
Produce and fetch request latency
Splits time into queue, local, remote and response time
Key takeaway: Kafka performance is a measured trade-off between throughput, latency, data integrity and cost. Size partitions for real parallelism, tune producers and consumers against metrics rather than folklore, and automate alerts for lag, under-replicated partitions and broker I/O so regressions surface early.
Frequently asked questions
What is the fastest way to diagnose poor Kafka performance?
Start with consumer lag, under-replicated partitions and produce and fetch latency. Those three usually show whether the problem is on the read path, the write path or the brokers themselves.
How many partitions should a Kafka topic have?
Enough for your target consumer parallelism and throughput, and no more. Extra partitions increase rebalance time, memory use and metadata load without making the topic faster.
Does raising linger.ms always improve producer throughput?
It often improves batching for small messages, but it adds a deliberate delay. Measure p99 latency under load before and after; latency-sensitive producers may prefer a smaller linger.ms with a larger batch.size.
Should I tune brokers or clients first?
Tune the side that owns the bottleneck you measured. Client batching and consumer parallelism fix many “slow Kafka” problems without touching broker settings.
Is Kafka performance tuning different after KRaft?
Yes. Kafka 4.0 removed ZooKeeper, so controller behaviour, metadata limits and recovery steps change. Re-baseline partition counts, metadata-heavy workloads and recovery drills after migrating rather than copying old runbooks.