/polymath-streaming:kafka-performance-tuningfrom polymath-streaming
Tune Kafka throughput, latency and consumer lag — producer batching, acks, fetch, rebalances, broker IO. Not topology (streaming-design).
Ships in polymath-streaming. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Kafka is fast when it does large sequential IO in batches and slow when you make it do small, synchronous, or skewed work. Find which of producer, broker, or consumer is the limit before turning any knob.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
Not this when: you are designing topics, keys, and delivery semantics — polymath-streaming:streaming-design. For stateful stream jobs — stream-processing. Azure's managed equivalent — polymath-streaming:azure-event-hubs-design.
min.insync.replicas, partition counts, managed (MSK, Confluent Cloud, Aiven) or self-run.RequestHandlerAvgIdlePercent, network processor idle, ISR shrinks, under-replicated partitions, disk util/IO wait, consumer lag per partition and its trend). Without metrics, say what to collect first.Production caution. Config changes to brokers can cause rolling restarts and leader movement; client changes are lower risk. Recommend, stage, and measure one change at a time; the owner applies.
batch.size (64–256 KB for high volume; default 16 KB is small) and set linger.ms (5–50 ms) so batches fill; trade a few ms latency for large throughput gains and fewer requests.compression.type lz4 (fast) or zstd (higher ratio) — batch compression multiplies effective network and disk throughput; measure CPU.acks=all with replication.factor=3, min.insync.replicas=2 for no-loss; acks=1 trades safety for latency (document the loss window). enable.idempotence=true (default in recent clients) gives per-partition ordering and dedup with up to 5 in-flight; transactions only if you need exactly-once across topics.buffer.memory, max.block.ms, delivery.timeout.ms sized so back-pressure surfaces as a handled error, not an unbounded stall; many small producers → shared producer instance per process (a producer is thread-safe).num.network.threads, num.io.threads, num.replica.fetchers when handler idle percent is low and CPU is available; check request-queue time before raising.replica.lag.time.max.ms; keep unclean.leader.election.enable=false for durable topics; rack-aware placement for AZ fault tolerance (cross-AZ replication traffic has a cost).auto.leader.rebalance.enable, Cruise Control) to avoid hot brokers.log.segment.bytes/log.retention.* tuned for delete cost and compaction; tiered storage (KIP-405, production-ready in recent versions) for long retention with cheap storage; limits listed in polymath-database:data-retention-archiving.producer_byte_rate, consumer_byte_rate, request quotas) protect the cluster from one noisy client.fetch.min.bytes + fetch.max.wait.ms for fewer, bigger fetches; max.partition.fetch.bytes; max.poll.records sized so processing fits within max.poll.interval.ms (exceeding it kicks the consumer out → rebalance loop).CooperativeStickyAssignor), static membership (group.instance.id + longer session.timeout.ms) for rolling deploys, fast shutdown with commit; don't do long work inside the poll thread without heartbeats.enable.auto.commit=false, commit after processing, batched (sync per batch or async with a final sync) — commit frequency is a hidden throughput cost.streaming-design).replica/follower fetching from nearest replica (KIP-392) for consumers to cut cross-AZ cost, and sizing NICs (broker out-bandwidth = replication + consumers × bytes-in).polymath-scalability:capacity-estimation for sizing): per-broker ingress = produce MB/s × RF ÷ brokers; egress = ingress × (RF − 1)/RF replication + consumer groups × produce MB/s; keep disks and NICs under ~60–70% at peak so a failed broker's load fits on the rest.Kafka tuning review: clickstream (Kafka 3.7, 9 brokers m5.2xlarge, RF 3, min.insync 2)
Symptom: consumer group "sessionizer" lag 18 min and growing; producers fine.
Evidence: bytes-in 140 MB/s steady; broker handler idle 62%, disk util 35%; sessionizer has 24 consumers on a 24-partition topic; partition 17 holds 31% of messages (key = country, "US"); per-record processing 4.1 ms with one DB call each.
Bottleneck: consumer — skewed partition + per-record DB round trips. Not brokers.
Changes (in order)
1. Consumer: batch DB writes per poll (max.poll.records 500) → est. ≥ 5× records/s per consumer [VERIFY: measure]; commit after each batch.
2. Key: change key from country to session_id (new topic version + dual-publish window, see streaming-design); until then isolate partition 17 with a dedicated consumer instance.
3. Rebalance: CooperativeStickyAssignor + group.instance.id, session.timeout 45 s (rolling deploys currently cause 90 s full stalls).
Producer (optional, cost): linger.ms 5→20, batch.size 16 KB→128 KB, compression lz4 → ~40% less network [VERIFY: measured ratio].
Broker: no change — handler idle 62%, disk 35%.
Verify: lag age < 1 min, p99 per-batch time, partition-level lag evenness, rebalance count/day.
Unknowns: [TBD: consumer GC/heap behavior at 500-record batches]
acks, replication, min.insync.replicas) state the loss window.acks=0/1 or min.insync.replicas=1 for speed on data that must not be lost, without a documented loss window.max.poll.records with slow processing — rebalance storm.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub mohammadbafkar/polymath --plugin polymath-streaming9 skills in this plugin
/azure-event-hubs-designDesign and size Azure Event Hubs — tier, throughput units, partitions, consumer groups, checkpointing, Capture, Kafka endpoint./data-lake-layoutDesign the physical data lake — zones, paths, Parquet and Delta/Iceberg, file sizing, partitioning, compaction, lifecycle tiers./data-modelingModel analytical data — dimensional (star/snowflake) vs normalized vs lakehouse medallion layers, grain, partitioning, slowly-changing dimensions, and schema evolution.Other plugins' skills for the same job