PleinIQ
Menu
Language

Choose your language

This page is only in English for now. Choosing a language opens its home page.

Other languages

Your browser can translate any page into almost any language.

Other browsers: Open the browser menu and look for “Translate”.

Your resume, your downloads and lab commands are never translated.

Roadmaps / Kafka / Lab 1

Lab 1 of 8 · Kafka basics: brokers, topics and partitions

Start Kafka and send your first events

Create a lab server, run a Kafka broker on it, and produce and consume keyed events across three partitions.

Time
60 minutes
Cost
Free. Everything runs on your own computer.

What you learn

Kafka stores events in topics, split into partitions and kept on brokers. You start a real Kafka broker on a free lab server, create a topic, and see how keys decide which partition an event lands in.

  • What brokers, topics, partitions and offsets are
  • Running Kafka in KRaft mode (no ZooKeeper) with Docker
  • Producing and consuming with the command-line tools
  • Why events with the same key stay in order

In the AI era: AI assistants explain Kafka concepts well, but they often mix up older ZooKeeper-era commands with today’s KRaft setup. Check every command against the Kafka documentation for your version.

Get set up

Commands use Homebrew in the Terminal app. Already have a tool? Skip it.

  • Install
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Use the Terminal app. The command installs Homebrew, which the other macOS commands use.

  • A free GitHub accountOfficial sign-up ↗
  • Multipass (a free Ubuntu server on your computer)Official install page ↗
    Install
    brew install --cask multipass

    Check it worked: multipass version

Before you start

  • Your computer needs about 15 GB of free disk space and 8 GB of memory (the lab server uses 4 GB).

Step by step

  1. 1 Create your lab server

    This starts an Ubuntu 24.04 server called kafka-lab on your computer. Kafka, Python and everything else in this roadmap run there.

    Run this in Terminal
    multipass launch 24.04 --name kafka-lab --cpus 2 --memory 4G --disk 15G
    multipass list
    You should see:

    kafka-lab is Running with an IPv4 address.

  2. 2 Open a shell on it

    From now on, steps labelled "Run this on your lab server" run in this shell. Type exit to leave it.

    Run this in Terminal
    multipass shell kafka-lab
    You should see:

    Your prompt changes to ubuntu@kafka-lab:~$.

  3. 3 Install Docker, Python and the GitHub CLI

    Adding yourself to the docker group lets you run Docker without sudo. When it finishes, type exit, then run multipass shell kafka-lab again so the group change applies.

    Run this on your lab server
    sudo apt-get update
    sudo apt-get install -y docker.io docker-compose-v2 python3-venv gh jq
    sudo usermod -aG docker "$USER"
    You should see:

    The packages install without errors.

  4. 4 Start a Kafka broker

    The official apache/kafka image starts a single-node cluster in KRaft mode, where Kafka manages its own metadata. It listens on localhost:9092 on your lab server. The kafka shell function saves typing: kafka topics ... runs kafka-topics.sh inside the container.

    Run this on your lab server
    docker run -d --name kafka --restart unless-stopped -p 9092:9092 apache/kafka:4.1.0
    echo 'kafka() { docker exec -i kafka "/opt/kafka/bin/kafka-$1.sh" --bootstrap-server localhost:9092 "${@:2}"; }' >> ~/.bashrc
    source ~/.bashrc
    sleep 15
    kafka topics --list && echo "Kafka is up"
    You should see:

    Kafka is up (the topic list is empty for now).

  5. 5 Create a topic with three partitions

    A partition is an ordered log. More partitions let more consumers read in parallel.

    Run this on your lab server
    kafka topics --create --topic first-orders --partitions 3
    kafka topics --describe --topic first-orders
    You should see:

    PartitionCount: 3, and one line per partition with Leader: 1 (your only broker).

  6. 6 Produce keyed events

    Each line is key:value. The key is the customer, so all of one customer’s orders go to the same partition and stay in order.

    Run this on your lab server
    printf 'alice:book\nbob:pen\ncarol:lamp\ndave:mug\nalice:desk\nerin:chair\n' | kafka console-producer --topic first-orders --property parse.key=true --property key.separator=:
    You should see:

    No output means the events were written.

  7. 7 Read them back

    The consumer prints each event’s partition and key. Notice that both of alice’s orders share a partition, while other customers are spread across partitions 0, 1 and 2.

    Run this on your lab server
    kafka console-consumer --topic first-orders --from-beginning --property print.partition=true --property print.key=true --timeout-ms 5000
    You should see:

    Six lines such as Partition:0 alice book. The command stops by itself after 5 seconds with no new events.

  8. 8 Connect GitHub and create your repository

    Use your own name and GitHub email. gh auth login shows a one-time code and a web address: open the address in the browser on your computer and enter the code.

    Run this on your lab server
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    gh auth login --hostname github.com --git-protocol https --web
    gh auth setup-git
    gh repo create kafka-streaming-lab --public --add-readme --clone
    cd kafka-streaming-lab
    You should see:

    A new kafka-streaming-lab folder that you are now inside.

  9. 9 Write your notes

    Create it with mkdir -p notes && nano notes/01-basics.md (save with Ctrl+O, exit with Ctrl+X).

    File: notes/01-basics.md
    # Kafka basics
    
    - Broker: ...
    - Topic: ...
    - Partition: ...
    - Offset: ...
    - Which partition each customer landed in: ...
    - Why one customer's orders stay in order: ...
    
  10. 10 Commit, push and stop the server

    Type exit after pushing, then stop the server from your computer. Kafka starts again with it next time.

    Run this on your lab server
    git add notes
    git commit -m "Add Kafka basics notes"
    git push
    You should see:

    The commit appears on GitHub. Then run multipass stop kafka-lab on your computer.

You are done when

  • A Kafka broker runs on your lab server.

  • first-orders has three partitions and six events.

  • Your notes explain why keyed events stay in order.

Finished? Get your proof page

We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.

Join PleinIQ Updates

What are you interested in?

Read how we handle your information in our privacy notice.