blog by OSO

Kafka performance best practices for monitoring and alerting

Sion Smith
Sion Smith 12 July 2023
OSO guide to Kafka performance best practices covering partitions, producer and consumer tuning, and monitoring alerts, with white title text on a navy panel and a lime Blogs label.

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.

For partition-aware application design, see how to build high-performance Kafka Streams applications.

How do you improve Kafka consumer performance?

Consumer lag is the headline Kafka performance metric for most reading workloads. Three levers dominate:

  1. 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.
  2. 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.
  3. 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.

Pair this section with the Kafka consumer configuring cheatsheet when you adjust client settings.

How do you optimise Kafka producers without losing durability?

Producer tuning is where throughput and data integrity trade off most clearly:

SettingWhat it controlsPerformance guidance
acksHow many replicas must confirm a writeacks=all with a suitable min.insync.replicas favours durability; weaker acks cut latency but widen the failure window
batch.sizeMaximum bytes per partition batchLarger batches improve throughput and compression for small messages
linger.msHow long the client waits to fill a batchA few milliseconds often helps throughput; measure p99 latency before and after
buffer.memoryMemory for records waiting to be sentMust absorb bursts; when full, send() blocks, which shows up as application latency
compression.typeCodec applied to each batchlz4 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.

MetricWhy it mattersAlert when
Active controller countShows 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 partitionsFollowers falling behind put durability at riskAbove zero for several minutes
Offline partitionsPartitions with no leader can’t be read or writtenAbove zero
Consumer lagShows whether consumers keep up, by group and partitionLag grows steadily rather than recovering
Produce and fetch request latencySplits time into queue, local, remote and response timep99 rises above your SLO
Disk usage and I/O waitFull or slow disks stall writes and replicationUsage passes your headroom threshold
Network throughputSaturated broker interfaces cap throughputSustained use near link capacity

Open source stacks such as Prometheus and Grafana remain the common baseline. Aim for actionable alerts rather than dashboards nobody reads. Our roundup of Kafka monitoring tools compares the options, and command-line operators should see 7 must-have CLI tools every Apache Kafka engineer should know.

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.

Tune your Kafka performance with OSO

Talk to OSO's Kafka engineers about finding your real bottleneck, tuning producers and consumers, and setting up alerts that catch regressions early.

CONTACT US
OSO
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.