Apache Kafka — Event Streaming from Basics to a Platform Service›Foundations · Cheat sheet & self-check

Foundations · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · Kafka, EFK and monitoring: who does what

Which tool answers which question?

Is the service healthy? How many requests, how slow, how full?Monitoring: Prometheus + Grafana (metrics)
What exactly happened in this request? Show me the errorLogging: EFK or Loki (log lines)
Where did this request spend its time across services?Tracing: OpenTelemetry + Tempo/Jaeger
Other systems must react to 'order placed'Kafka (events)
Several systems need the same data, now and laterKafka (events, replay)

How data gets in

PrometheusPulls: scrapes each app's /metrics endpoint every 15–30 s
EFKPushed: Fluent Bit reads log files and sends them to Elasticsearch
KafkaPushed by producers (your code, Fluent Bit, Debezium); consumers pull at their own pace

02 · Why event streaming

Words to know

EventA fact that happened: 'order 123 was placed'. Immutable once written
ProducerA program that writes events
ConsumerA program that reads events, at its own pace
TopicA named stream of events, such as orders
LogAn append-only, ordered list of events kept for a retention period
ReplayReading old events again, from any point still retained

Log or queue?

Many independent readers of the same dataLog (Kafka)
Need to re-read historyLog (Kafka)
Hand out tasks to workers, delete when doneQueue (RabbitMQ, SQS)
Request needs an answer nowNeither: use an API call

03 · Core concepts

The pieces

BrokerOne Kafka server; stores partitions and serves clients
ClusterSeveral brokers working together (3 or more in production)
TopicA named stream of records
PartitionAn ordered, append-only log; a topic has one or more
OffsetA record's position number in its partition
Consumer groupConsumers sharing the work; each partition goes to one member
Replication factorHow many brokers hold a copy of each partition
KRaft controllerKeeps the cluster's metadata; replaced ZooKeeper

Rules worth memorising

OrderGuaranteed only within one partition
Same keySame partition (while the partition count is unchanged)
Group parallelismAt most one active consumer per partition per group
ReadingNever deletes data; retention does

04 · Lab: your first Kafka cluster

Run Kafka

docker run -d --name kafka -p 9092:9092 apache/kafka:4.1.0Single-node KRaft cluster (broker + controller)
docker exec -it kafka bashShell inside; tools are in /opt/kafka/bin
docker rm -f kafkaRemove it

Topics

kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3 --replication-factor 1Create a topic
kafka-topics.sh --bootstrap-server localhost:9092 --listList topics
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic ordersPartitions, leaders, replicas, ISR
kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name orders --alter --add-config retention.ms=86400000Change a topic setting
kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic ordersLatest offset per partition

Produce and consume

kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders --property parse.key=true --property key.separator=:Type key:value lines
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning --group billing --property print.key=true --property print.partition=true --property print.offset=trueRead with a group, showing key, partition, offset

Groups

kafka-consumer-groups.sh --bootstrap-server localhost:9092 --listList groups
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billingOffsets and lag per partition
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group billing --topic orders --reset-offsets --to-earliest --executeReplay from the start (group must be stopped)

05 · Lab: Kafka on your Kubernetes cluster

Install and create

helm repo add strimzi https://strimzi.io/charts/Add the Strimzi chart repository
helm install strimzi strimzi/strimzi-kafka-operator --version 1.3.1 -n kafka --create-namespaceInstall the operator
kubectl apply -f kafka-lab.yamlCreate the KafkaNodePool and Kafka resources
kubectl wait kafka/lab -n kafka --for=condition=Ready --timeout=10mWait until the cluster is ready
kubectl get kafka,kafkanodepool,kafkatopic,pods,pvc,svc -n kafkaSee everything Strimzi created

Use it

k() { kubectl -n kafka exec -it lab-dual-role-0 -- "$@"; }Helper: run a Kafka CLI tool inside a broker pod
k bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic ordersPartitions, leaders and ISR
k bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billingGroup offsets and lag
lab-kafka-bootstrap.kafka.svc:9092The address applications use
kubectl -n kafka delete pod lab-dual-role-2Simulate a broker failure