Skip to content
Back to skills

Kafka Best Practices

ASecurity

Apache Kafka 4.2 best practices for event streaming, topic design, and producer-consumer patterns

  • 43 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 9, 2026
documentationapiperformancedocumentation

Works with

  • api

Security analysis

A100/100

Scanned September 9, 2026

npx -y skills add baekenough/oh-my-customcode --skill kafka-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Kafka Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Kafka Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/baekenough-kafka-best-practices/badge)](https://www.skillsdirectory.com/skills/baekenough-kafka-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: kafka-best-practices
description: Apache Kafka 4.2 best practices for event streaming, topic design, and producer-consumer patterns
scope: core
user-invocable: false
---

# Apache Kafka Best Practices

> **Version**: Kafka 4.2.0. ZooKeeper is fully removed in Kafka 4.x — use KRaft mode for all cluster deployments.

## Producer Patterns

### Idempotent Producer (CRITICAL)
- Enable `enable.idempotence=true`
- Prevents duplicate messages
- Requires `acks=all`, `retries > 0`, `max.in.flight.requests.per.connection <= 5`

### Exactly-Once Semantics
- Use transactional API: `initTransactions()`, `beginTransaction()`, `commitTransaction()`
- For exactly-once end-to-end processing

### Performance
- Batching: `linger.ms` (wait for batch to fill)
- Compression: `compression.type=snappy` or `lz4`
- `batch.size`: 16KB default, tune based on message size

## Consumer Patterns

### Offset Management
- Auto-commit: `enable.auto.commit=true` (at-least-once)
- Manual commit: `commitSync()` or `commitAsync()` (better control)

### Rebalancing
- Cooperative sticky assignor: minimal rebalancing disruption
- `session.timeout.ms` and `heartbeat.interval.ms` tuning

### At-Least-Once vs Exactly-Once
- At-least-once: default, idempotent processing required
- Exactly-once: transactional consumer + producer

## Topic Design

### Partitioning
- Partition count: based on throughput (MB/s ÷ partition throughput)
- Key-based partitioning for ordering guarantees
- More partitions = higher throughput (but more overhead)

### Retention
- Time-based: `retention.ms`
- Size-based: `retention.bytes`
- Log compaction: for changelog topics (`cleanup.policy=compact`)

## References
- [Kafka Documentation](https://kafka.apache.org/documentation/)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.