This is a complete, hands-on Apache Kafka cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.
Kafka is a distributed log for streaming events: producers append to partitioned topics, consumers read at their own pace, and data is durably replicated - the backbone of event-driven architectures.
Why you reach for it
- High throughput with durable, replayable, ordered partitions
- Decouples producers and consumers for resilient pipelines
- A rich ecosystem (Connect, Streams, Schema Registry)
Installation
docker run -p 9092:9092 apache/kafka:latest
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3Configuration reference
Produce and consume with the Python client.
from kafka import KafkaProducer, KafkaConsumer
p = KafkaProducer(bootstrap_servers='localhost:9092')
p.send('orders', b'{"id": 42}'); p.flush()
c = KafkaConsumer('orders', bootstrap_servers='localhost:9092', group_id='billing')
for msg in c:
print(msg.value)Core commands you use daily
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billingTopics
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3 --replication-factor 2
kafka-topics.sh --bootstrap-server localhost:9092 --list
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic ordersProduce, consume, groups
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --reset-offsets --to-earliest --group billing --topic orders --executeUse it in CI/CD
Spin up Kafka as a CI service for integration tests.
services:
kafka:
image: apache/kafka:latest
ports: ['9092:9092']Best-practice checklist
- Size partitions for target consumer parallelism up front
- Monitor consumer lag and set alerts on it
- Use a Schema Registry and compatibility rules
Common pitfalls to avoid
- Too few partitions, capping consumer parallelism
- Ignoring consumer lag until it becomes an outage
- No schema management, so producers break consumers
Security quick wins
- Enable TLS and SASL auth; set ACLs per topic and group
- Encrypt data at rest and restrict inter-broker access
Works well with
- Redis - An in-memory data store used as a cache, session store, queue and rate limiter.
- rabbitmq
- Kubernetes - Declarative orchestration for containers at scale - self-healing, rolling updates and service discovery.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.
Want senior help putting Apache Kafka to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.