Foundations · wrap-up
Cheat sheet & self-check
Every command from this section on one page.
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 error | Logging: 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 later | Kafka (events, replay) |
How data gets in
Prometheus | Pulls: scrapes each app's /metrics endpoint every 15–30 s |
EFK | Pushed: Fluent Bit reads log files and sends them to Elasticsearch |
Kafka | Pushed by producers (your code, Fluent Bit, Debezium); consumers pull at their own pace |
Words to know
Event | A fact that happened: 'order 123 was placed'. Immutable once written |
Producer | A program that writes events |
Consumer | A program that reads events, at its own pace |
Topic | A named stream of events, such as orders |
Log | An append-only, ordered list of events kept for a retention period |
Replay | Reading old events again, from any point still retained |
Log or queue?
Many independent readers of the same data | Log (Kafka) |
Need to re-read history | Log (Kafka) |
Hand out tasks to workers, delete when done | Queue (RabbitMQ, SQS) |
Request needs an answer now | Neither: use an API call |
The pieces
Broker | One Kafka server; stores partitions and serves clients |
Cluster | Several brokers working together (3 or more in production) |
Topic | A named stream of records |
Partition | An ordered, append-only log; a topic has one or more |
Offset | A record's position number in its partition |
Consumer group | Consumers sharing the work; each partition goes to one member |
Replication factor | How many brokers hold a copy of each partition |
KRaft controller | Keeps the cluster's metadata; replaced ZooKeeper |
Rules worth memorising
Order | Guaranteed only within one partition |
Same key | Same partition (while the partition count is unchanged) |
Group parallelism | At most one active consumer per partition per group |
Reading | Never deletes data; retention does |
Run Kafka
docker run -d --name kafka -p 9092:9092 apache/kafka:4.1.0 | Single-node KRaft cluster (broker + controller) |
docker exec -it kafka bash | Shell inside; tools are in /opt/kafka/bin |
docker rm -f kafka | Remove it |
Topics
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3 --replication-factor 1 | Create a topic |
kafka-topics.sh --bootstrap-server localhost:9092 --list | List topics |
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders | Partitions, leaders, replicas, ISR |
kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name orders --alter --add-config retention.ms=86400000 | Change a topic setting |
kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic orders | Latest 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=true | Read with a group, showing key, partition, offset |
Groups
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list | List groups |
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing | Offsets and lag per partition |
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group billing --topic orders --reset-offsets --to-earliest --execute | Replay from the start (group must be stopped) |
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-namespace | Install the operator |
kubectl apply -f kafka-lab.yaml | Create the KafkaNodePool and Kafka resources |
kubectl wait kafka/lab -n kafka --for=condition=Ready --timeout=10m | Wait until the cluster is ready |
kubectl get kafka,kafkanodepool,kafkatopic,pods,pvc,svc -n kafka | See 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 orders | Partitions, leaders and ISR |
k bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing | Group offsets and lag |
lab-kafka-bootstrap.kafka.svc:9092 | The address applications use |
kubectl -n kafka delete pod lab-dual-role-2 | Simulate a broker failure |