Skip to content

About

Run a single-node Kafka 4 cluster in KRaft mode and practice topics, producers, and consumers.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Arya Fatthurahman

Apache Kafka Lab

Run a single-node Kafka 4 cluster in KRaft mode and practice topics, producers, and consumers.

Database: Apache Kafka Category: Event streaming Runs in Docker License: MIT compose-check

What this lab is

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.

Quickstart

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

Connection details

Field Value
Bootstrap server localhost:9092
Topic lab-events
Partitions 3
Replication factor 1
CLI path /opt/kafka/bin

Examples

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.

Exercises

  1. Produce 100 events and inspect the per-partition offsets with kafka-consumer-groups.sh --describe.
  2. Create a compacted topic and explain the difference from a delete-retention topic.
  3. Add a second broker and set the replication factor to 2.
  4. Write a small producer/consumer in Python with kafka-python or confluent-kafka.

Notes and limits

  • This is a single-node KRaft cluster. It is not a production topology.
  • KAFKA_ADVERTISED_LISTENERS uses localhost, 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-data volume keeps topic data across restarts.
  • Kafka 4 removed ZooKeeper; this lab uses the built-in KRaft controller.

Run it from anywhere

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.

Cleanup

docker compose down -v

-v also removes the named volume, so the next start is a clean slate.

References


Part of the database-labs collection: 26 database engines, one index.

License

MIT (c) 2026 Arya Fatthurahman. See LICENSE.

About

Run a single-node Kafka 4 cluster in KRaft mode and practice topics, producers, and consumers.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors