Run a single-node Kafka 4 cluster in KRaft mode and practice topics, producers, and consumers.
Kafka is the backbone of event-driven architectures. This lab runs the official Apache Kafka image in KRaft mode (no ZooKeeper), creates a topic, produces JSON events, and consumes them from the command line.
docker compose up -d
bash examples/01_create_topic.sh
bash examples/02_produce.sh
bash examples/03_consume.sh
docker compose exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic lab-events| Field | Value |
|---|---|
| Bootstrap server | localhost:9092 |
| Topic | lab-events |
| Partitions | 3 |
| Replication factor | 1 |
| CLI path | /opt/kafka/bin |
| File | What it shows |
|---|---|
docker-compose.yml |
Engine, ports, and persistent volume. |
.github/workflows/compose-check.yml |
Validates the Compose file on every push. |
examples/01_create_topic.sh |
Create a three-partition topic. |
examples/02_produce.sh |
Produce three JSON events. |
examples/03_consume.sh |
Consume from the beginning and print message keys and values. |
- Produce 100 events and inspect the per-partition offsets with
kafka-consumer-groups.sh --describe. - Create a compacted topic and explain the difference from a delete-retention topic.
- Add a second broker and set the replication factor to 2.
- Write a small producer/consumer in Python with
kafka-pythonorconfluent-kafka.
- This is a single-node KRaft cluster. It is not a production topology.
KAFKA_ADVERTISED_LISTENERSuseslocalhost, so clients running in other containers cannot reach the broker with that address. Add a second listener if you need container-to-container access.- The
kafka-datavolume keeps topic data across restarts. - Kafka 4 removed ZooKeeper; this lab uses the built-in KRaft controller.
This lab publishes its ports on 127.0.0.1 only. To use it from another country, do not open the database port to the internet. Pick one:
- VPS + private tunnel: run the lab on a small Ubuntu VPS, keep the port closed, and connect through WireGuard or
ssh -L. - Managed service: use a managed free tier for this engine and point the same examples at its connection string.
- HTTP UI only: if the engine has a web UI, put it behind Caddy with TLS and basic auth.
The shared checklist, provider map, and commands are in REMOTE-ACCESS.md.
docker compose down -v-v also removes the named volume, so the next start is a clean slate.
Part of the database-labs collection: 26 database engines, one index.
MIT (c) 2026 Arya Fatthurahman. See LICENSE.