Checking your sign-in…
This lesson is in Phase 1 — ₹399, one-time
Pay once with UPI, card or netbanking. Keep it forever. Your progress saves, so you can stop and come back.
← Back to all lessonsKafka Lab — Messages in a Line
Phase 1 · The Data TierWhat this is and why it matters
Kafka is a line of messages waiting to be read.
Think of a kitchen rail with order slips on it.
- A cook writes an order slip and hangs it on the rail.
- The rail holds the slips in order, first slip first.
- Another cook takes the slips off the rail, one by one, in order.
- The slips stay on the rail even after they are read, until the kitchen clears them.
Kafka is that rail, for computer programs.
- One program writes messages into a line. That program is called a producer. A producer is a writer.
- Another program reads messages out of the line. That program is called a consumer. A consumer is a reader.
- The line itself is called a topic. A topic is one named line.
- The machine that holds the line is called a broker. A broker is one Kafka server.
- One or more brokers together are called a cluster. A cluster is a group of brokers working as one.
Why does this matter?
- If the reader is slow, the messages wait safely on the rail. Nothing is lost.
- If the reader stops, the messages are still there when it comes back.
- Many readers can read the same line.
In this lab you run TWO small clusters on your own machine.
- Cluster a is the main one. You send 3 fake orders into it.
- Cluster b is the copy. A tool called MirrorMaker 2 copies the orders from cluster a to cluster b.
- If cluster a dies, cluster b still has the copy. That is the whole point.
All data in this lab is fake. Order numbers and item names you make up. Nothing real is bought or sold.
Test status
Syntax-checked only (20 November 2026). The compose file and the properties files were checked for correct syntax. This lab was NOT run end-to-end on a real machine here. Follow it on your own machine with Docker, and if a step fails, read the error first — that is the real skill.
Words you need here
Learn these first. The lesson uses them before it explains some of them — this list explains them before you meet them.
- Terminal — a window where you type what you want the computer to do.
- Docker — a free program that runs sealed boxes on your machine. Each box runs one program. The boxes are called containers.
- Container — a sealed box that runs one program. Here each Kafka cluster lives in its own box.
- Image — the recipe file Docker downloads once, then uses to build a box. The first start downloads the Kafka image, so it takes a few minutes.
- Compose file — a recipe file named
docker-compose.yml. It lists the boxes to start and how they connect. Docker Compose reads it and starts everything in one go. - Topic — one named line of messages. This lab uses one topic called
orders. - Producer — a program that puts messages into a topic. A writer.
- Consumer — a program that takes messages out of a topic. A reader.
- Broker — one Kafka server. A cluster is one or more brokers. In this lab each cluster has exactly ONE broker. So "two clusters" here means two single boxes: one called kafka-a, one called kafka-b.
- MirrorMaker 2 (MM2) — a tool that copies topics from one cluster to another. It lives in its own box, called mm2.
- Partition — a topic is split into parts. This lab uses 1 part.
- Replication factor — how many copies of each message Kafka keeps. This lab keeps 1 copy.
- localhost — a name that means "this machine, the one I am sitting at".
- Port — a door number on a machine. Kafka's door is 9092. When you see
localhost:9092, read it as "this machine, door 9092". - Log — a written record of what a program did. When something breaks, you read the log. It is the program telling you what went wrong.
- Ctrl+C — hold the Ctrl key and press C. It stops the program that is running in your terminal right now, and gives you your terminal back.
Before you start — do these first
1. Docker must be running
WHAT it is: Docker is the free program that runs the boxes for this lab. Without it, nothing starts.
WHY you need it: every part of this lab — both Kafka clusters and MirrorMaker 2 — runs inside Docker boxes. No Docker, no lab.
HOW: do Lesson 0 first (it checks Docker is installed and running), and read the Zero-Cost Lab in Phase 2 if Docker is not installed yet. The file on your machine is phase2/zero-cost-lab.md. Yes, it lives in Phase 2 even though this is a Phase 1 lab — Docker setup is taught there, so read it first if you have never installed Docker.
2. Open a terminal
WHAT it is: a window where you type commands.
WHY: every step in this lab is a typed command. There is nothing to click.
HOW: open the terminal app on your machine (Terminal on Mac, Windows Terminal or Git Bash on Windows, any terminal on Linux).
3. Go into the lab folder
WHAT it is: the folder that holds this lab's files.
WHY: the commands in this lab only work when you run them from inside this folder. The recipe file docker-compose.yml lives here, and Docker Compose reads the recipe from the folder you are standing in.
HOW: type this command. cd means "change directory" — move into a folder.
cd phase1/kafka-labThe full folder is phase1/kafka-lab inside the kit folder you downloaded.
Check you are in the right place. Type:
lsls means "list" — show me the files here. You should see exactly these three files:
connect-standalone.properties
docker-compose.yml
mm2.propertiesIf you see them, you are in the right folder. If not, you are in the wrong folder — go back and cd again.
4. The three files, and what each one is for
docker-compose.yml— the recipe. It tells Docker Compose to start three boxes: kafka-a (cluster a), kafka-b (cluster b), and mm2 (MirrorMaker 2). It also says cluster a answers on door 9092 and cluster b answers on door 9094 on your machine.mm2.properties— the settings for MirrorMaker 2. It says: the two clusters are named a and b; cluster a lives atkafka-a:9092; cluster b lives atkafka-b:9092; copy from a to b, one way only; copy only the topic namedorders. The threereplication.factor=1lines matter because each cluster has only one node — the small topics MirrorMaker 2 makes for itself must also use 1 copy, not 3. Without those lines, MirrorMaker 2 fails to start.connect-standalone.properties— the settings for the MirrorMaker 2 worker itself. It says where the worker keeps its own small notes (which messages it has already copied). You never type into this file and never change it in this lab. It just needs to be there.
One important thing first
Kafka tells every client the address to come back to. In this lab that address is the box's own name (kafka-a), so Kafka commands must run INSIDE the box. Your own machine does not know the name kafka-a. That is why every Kafka command starts with docker exec kafka-a — it means "go inside the kafka-a box and run this there". This is normal. It is not a mistake.
docker exec means "execute" — run a command inside a box. exec is short for "execute", which means "run".
Step 1 — Start both clusters
WHAT this step is: starting all three boxes at once — cluster a, cluster b, and MirrorMaker 2.
WHY we do it: nothing else in this lab works until the clusters are running. The topics, the messages and the copy all need live clusters.
The command, broken down word by word:
docker compose up -ddocker— the tool that runs boxes.compose— read the recipe file (docker-compose.yml) in this folder.up— start everything the recipe lists.-d— run in the background. The-dmeans "detached". It gives you your terminal back at once, so you can type the next command while the boxes keep running behind you. Without-d, the terminal would fill with logs and you could not type.
Run it from inside phase1/kafka-lab:
docker compose up -dWhat you should see, line by line:
[+] Running 3/3
✔ Container kafka-a Started
✔ Container kafka-b Started
✔ Container mm2 Started[+] Running 3/3— all 3 boxes in the recipe started. 3 out of 3.✔ Container kafka-a Started— the box for cluster a started.✔ Container kafka-b Started— the box for cluster b started.✔ Container mm2 Started— the box for MirrorMaker 2 started.
How to tell it worked: all three lines say Started, and the count says 3/3. If you see 3/3, you are good.
First time only: the first start downloads the Kafka image, so it takes a few minutes. You will see download lines scrolling past — that is the image coming down. Wait until the scrolling stops and the Started lines appear. Do not press anything while it downloads.
Now check that all three boxes are still up. WHAT this check is: asking Docker Compose to list the boxes and their state. WHY: a box can start and then stop again at once if something is wrong — the Started lines do not prove it stayed up.
docker compose psdocker compose— the tool, reading the recipe in this folder.ps— "process status". List the boxes and say whether each one is up or stopped.
What you should see:
NAME STATUS
kafka-a Up
kafka-b Up
mm2 Up(The real table has more columns. What matters is all three names, each with STATUS Up.)
How to tell it worked: all three names are there, and each one says Up. Up means running. mm2 may take a minute — it waits for both clusters before it is ready, so if it says Up a little later than the others, that is normal.
If it breaks:
- If a box says
Exitedinstead ofUp:Exitedmeans the box started and then stopped, like a program that crashed on launch. Read its log:
docker compose logs mm2logs— show me the written record of what this box did. Read the last lines. Look for the wordERROR— that line says what went wrong.- If it still breaks: stop everything and start again:
docker compose downdown means stop the boxes and remove them. Then run docker compose up -d again.
Step 2 — Make the topic
WHAT this step is: creating the line the messages will wait in. The line is called orders.
WHY we do it: a producer cannot send messages into a line that does not exist yet. Make the line first, then send.
The command, broken down word by word:
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 1 --replication-factor 1docker exec— run a command INSIDE a box.execmeans "execute".kafka-a— the box to go inside: cluster a./opt/kafka/bin/kafka-topics.sh— the program to run, by its full address inside the box./optis a folder where installed programs live.kafka-topics.shis the tool that makes and lists topics..shmeans it is a script — a small program made of typed commands.--bootstrap-server localhost:9092— "the Kafka server to talk to is this machine, door 9092".bootstrap-servermeans the first server to connect to.localhostmeans this machine.9092is Kafka's door number.--create— make something new (do not just list).--topic orders— the line to make is namedorders.--partitions 1— split the line into 1 part. One part is enough here.--replication-factor 1— keep 1 copy of each message. One copy is enough here because each cluster has only one broker.
Run it:
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 1 --replication-factor 1What you should see:
Created topic orders.One line. How to tell it worked: the line says Created topic orders. That is the whole proof.
If it breaks:
Topic 'orders' already exists— you already made it. Skip this step. Nothing is wrong.Connection refused— kafka-a is not up yet.Connection refusedmeans the door was closed: nobody answered. Wait a minute and rundocker compose psagain until kafka-a saysUp.
Step 3 — Send three fake messages
WHAT this step is: starting the producer — the writer — and typing three fake orders into it.
WHY we do it: a line with no messages proves nothing. We put messages in so we can read them back and watch them get copied.
The command, broken down word by word:
docker exec -it kafka-a /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic ordersdocker exec— run a command INSIDE a box.-it— two flags joined together.imeans interactive: let me type into this program.tmeans terminal: give me a proper typing screen. Together they mean "I want to type into this program, live". Without-it, the producer could not read what you type.kafka-a— the box to go inside: cluster a./opt/kafka/bin/kafka-console-producer.sh— the producer program. It reads lines you type and sends each line as one message.--bootstrap-server localhost:9092— the Kafka server to talk to: this machine, door 9092.--topic orders— send the messages into the line namedorders.
Run it. The screen will go quiet and wait. That is the producer waiting for your lines. Now type these three lines, pressing Enter after each one (fake orders — made up for this lab):
order-101, notebook, 250
order-102, pen, 40
order-103, mug, 350Then stop the producer. Hold Ctrl and press C:
Ctrl+CCtrl+C stops the program running in your terminal and gives you your terminal back. Each line you typed is now one message in the topic, in order.
What you should see: nothing while you type. The producer prints nothing and waits for your lines. That is normal. Silence here means it is working.
How to tell it worked: after Ctrl+C your normal terminal prompt comes back, with no error above it. The messages are in the topic — Step 4 proves it.
If it breaks: if the producer exits at once with an error about the topic, go back to Step 2 and check the topic exists:
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list--list— list the lines that exist, instead of making one.
You should see orders in the list:
ordersIf orders is there, run Step 3 again.
Step 4 — Read the messages back
WHAT this step is: starting the consumer — the reader — and asking it to read from the very start of the topic.
WHY we do it: to prove the messages are STORED in Kafka, not just sent and lost. If the consumer prints your three lines, Kafka kept them.
The command, broken down word by word:
docker exec kafka-a /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginningdocker exec— run a command INSIDE a box.kafka-a— the box to go inside: cluster a./opt/kafka/bin/kafka-console-consumer.sh— the consumer program. It reads messages out of a topic and prints them.--bootstrap-server localhost:9092— the Kafka server to talk to: this machine, door 9092.--topic orders— read from the line namedorders.--from-beginning— start from the very first message, not just new ones. Without this, the consumer would only show messages that arrive AFTER it starts — and your three messages arrived before, so you would see nothing.
Run it. You should see your three lines, in order:
order-101, notebook, 250
order-102, pen, 40
order-103, mug, 350Then press Ctrl+C to stop it. (If you do not stop it, it keeps waiting for new messages forever.)
How to tell it worked: the three lines you typed in Step 3 appear here, in the same order. Same lines, same order — Kafka stored them.
If it breaks: if you see nothing, check you typed the messages into the same topic (orders) on the same cluster (kafka-a). Kafka keeps messages even after you read them once, so reading again with --from-beginning shows them again — you can re-run this step as many times as you like.
Step 5 — Watch MirrorMaker 2 copy them
WHAT this step is: checking that the copy tool already did its job — the messages now live on cluster b too.
WHY we do it: this is the point of the whole lab. One cluster holds the messages; a second cluster holds the copy. If cluster a dies, cluster b still has them.
MirrorMaker 2 is already running in the mm2 box. It copies the orders topic from cluster a to cluster b. The copy appears on cluster b with the source name in front: a.orders. The a. in front means "this came from cluster a". That is normal MirrorMaker 2 behaviour — the name tells you where the messages came from.
First, list the topics on cluster b:
docker exec kafka-b /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --listThis is the same list command as Step 3's check, but inside kafka-b instead of kafka-a. You should see a.orders in the list (plus small topics MirrorMaker 2 makes for itself — those start with mm2- or heartbeats, ignore them):
a.ordersHow to tell it worked: a.orders is in the list. That means the copy exists on cluster b.
Now read the copied messages from cluster b:
docker exec kafka-b /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic a.orders --from-beginningSame consumer as Step 4, but inside kafka-b, and reading the topic a.orders instead of orders. You should see the same three lines:
order-101, notebook, 250
order-102, pen, 40
order-103, mug, 350Press Ctrl+C to stop it.
How to tell it worked: the same three lines appear on cluster b. The same messages now live on two clusters. If cluster a dies, cluster b still has the copy.
If it breaks: if a.orders is missing, wait one minute and list the topics again. MirrorMaker 2 copies every few seconds, not instantly — the copy takes a little time to appear. If it is still missing, check the MirrorMaker 2 log:
docker compose logs mm2Read the last lines. Look for the word ERROR. The most common cause is that MirrorMaker 2 started before kafka-b was ready — restart it:
docker compose restart mm2restart— stop this box and start it again, so it reads its settings fresh. Then wait a minute and list the topics again.
Step 6 — Send one more message and watch it follow
WHAT this step is: sending a fourth order to cluster a, then checking that the copy on cluster b picked it up by itself.
WHY we do it: to prove the copy is LIVE, not a one-time snapshot. A good copy follows new messages on its own. If the fourth order appears on cluster b without you doing anything else, the mirror is working continuously.
Send the fourth message. This is the same producer command as Step 3:
docker exec -it kafka-a /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic ordersType one line:
order-104, mouse pad, 150Press Ctrl+C.
What you should see: nothing while you type — the producer prints nothing, same as Step 3. That is normal.
Wait 30 seconds. The copy takes a few seconds to travel. Then read cluster b again:
docker exec kafka-b /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic a.orders --from-beginningorder-101, notebook, 250
order-102, pen, 40
order-103, mug, 350
order-104, mouse pad, 150Press Ctrl+C.
How to tell it worked: order-104 is there on cluster b. The copy follows new messages by itself — you did nothing to cluster b, and the new message still arrived there.
If it breaks: if order-104 is missing, wait one more minute and read again — the copy takes a few seconds, not instantly. If it is still missing, check the MirrorMaker 2 log with docker compose logs mm2 and look for ERROR.
Extra practice — break the mirror on purpose, then fix it
Do this after Step 6, while the clusters are still running. It teaches the skill the whole kit is built on: something breaks, you read the message, you fix the one thing that is wrong.
Break it
WHAT this step is: changing one line in MirrorMaker 2's settings so it points at the WRONG door — like a typo in the settings.
WHY we do it: to see what a broken mirror looks like, and to learn to read the log that says exactly what is wrong. Breaking it on purpose, where nothing real is at stake, is how you learn to fix it for real.
The command, broken down word by word:
sed -i 's/b.bootstrap.servers=kafka-b:9092/b.bootstrap.servers=kafka-b:9093/' mm2.propertiessed— a small tool that edits text in a file. Its name comes from "stream editor".-i— edit the file itself, in place. Without-i, sed would only print the changed text and the file would stay the same.'s/old/new/'— substitute: findold, replace it withnew.b.bootstrap.servers=kafka-b:9092— the old text: cluster b lives at door 9092. This is the correct door.b.bootstrap.servers=kafka-b:9093— the new text: cluster b lives at door 9093. Door 9093 is WRONG — nothing listens there. That is the break.mm2.properties— the file to change.
Run it from inside phase1/kafka-lab. What you should see: nothing. sed works quietly — no output means it worked. That silence is normal.
Now send a fifth order to cluster a, the same way as Step 3:
docker exec -it kafka-a /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic ordersType:
order-105, scissors, 90Press Ctrl+C.
This order lands in cluster a — and nowhere else, because the mirror is broken. Read cluster b to prove it: you will still see only four orders. order-105 is missing from cluster b.
Read the log
WHAT this step is: reading the last lines of MirrorMaker 2's written record.
WHY we do it: the log says plainly what went wrong. You do not have to guess.
MirrorMaker 2 runs inside the mm2 box, and its log is the box's own output. Read it with the same docker compose logs command from Step 1:
docker compose logs mm2logs— show me the written record of what this box did. Read the last lines. Look for the wordERROR— that line says what went wrong.
What you should see: a line like this (the exact time will differ):
ERROR Failed to connect to cluster b: connection refused (kafka-b:9093)Line by line:
ERROR— something failed. This is the word to look for in any log.Failed to connect to cluster b— MirrorMaker 2 could not reach cluster b.connection refused (kafka-b:9093)— the door was closed. It tried door 9093. That is the bad door you just typed.
Now confirm the bad door is in the settings file itself:
cat mm2.propertiescat— show me the whole file. (Its name comes from "concatenate".)
You will see this line in the output:
b.bootstrap.servers=kafka-b:9093There it is — the settings file itself points at 9093. The fix is one line.
Fix it
WHAT this step is: putting the right door back, then restarting MirrorMaker 2 so it reads the fixed settings.
WHY: the settings file is only read when the program starts. Changing the file is not enough — you must restart the program for it to notice.
Put the right door back. This is the same sed command as before, with the old and new text swapped:
sed -i 's/b.bootstrap.servers=kafka-b:9093/b.bootstrap.servers=kafka-b:9092/' mm2.propertiesNo output — that is normal. Then restart the mirror:
docker compose restart mm2restart— stop this box and start it again. It reads the fixed settings and copies the order that arrived while it was broken.
Wait a minute. Then read cluster b again:
docker exec kafka-b /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic a.orders --from-beginningorder-101, notebook, 250
order-102, pen, 40
order-103, mug, 350
order-104, mouse pad, 150
order-105, scissors, 90Press Ctrl+C.
How to tell it worked: order-105 is on cluster b at last. The mirror caught up on its own after the fix. You broke it, read the log, fixed one line, and it healed itself. That is the job.
Save your proof
Do this BEFORE the clean up below, while the clusters are still running. The proof for this lab is the mirrored messages on cluster b.
WHAT this step is: saving the four mirrored messages into a file, so you have proof the copy works.
WHY: a file you can show is worth more than a screen you saw once. This file is the proof you attach to your portfolio.
First make the proof folder. Run this from inside phase1/kafka-lab:
mkdir -p ../portfolio/proofmkdir— make a directory (a folder).-p— make the parent folders too if they are missing, and do not complain if the folder already exists.../portfolio/proof— the folder to make...means "one folder up". Fromphase1/kafka-lab, one folder up isphase1, so this makesphase1/portfolio/proof/. That is where all the kit's proof files live.
Then save the messages:
docker exec kafka-b /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic a.orders --from-beginning --timeout-ms 5000 > ../portfolio/proof/kafka-mirror.txtBroken down word by word:
docker exec kafka-b ...— run a command inside the kafka-b box, as before./opt/kafka/bin/kafka-console-consumer.sh— the consumer program.--bootstrap-server localhost:9092— the Kafka server: this machine, door 9092.--topic a.orders— read the copied line on cluster b.--from-beginning— start from the very first message.--timeout-ms 5000— stop by itself after 5000 milliseconds. 5000 milliseconds is 5 seconds.timeoutmeans "give up after this long". Without it, the consumer would wait forever and you would have to pressCtrl+C. With it, it stops by itself after 5 seconds. That is WHY it stops after 5 seconds: the timeout tells it to.>— send the output into a file instead of the screen. The>sign is called a redirect. Everything the consumer prints goes into the file, and nothing appears on your screen.../portfolio/proof/kafka-mirror.txt— the file to write into. One folder up from here, thenportfolio/proof/, file namedkafka-mirror.txt.
What you should see: nothing in the terminal when you run the save command. The messages went into the file, not the screen. Silence here means it worked.
Now open the file and check it holds all four messages, including order-104, mouse pad, 150:
cat ../portfolio/proof/kafka-mirror.txtorder-101, notebook, 250
order-102, pen, 40
order-103, mug, 350
order-104, mouse pad, 150How to tell it worked: all four lines are in the file. That file is your proof. (If you did the extra break-and-fix practice, run the save command after the fix and the file will hold all five messages — even better proof.)
If it breaks: if the file is empty, the consumer timed out before MirrorMaker 2 copied the messages — wait a minute, then run the save command again.
Clean up
WHAT this step is: stopping all three boxes and removing them.
WHY we do it: the lab is done. The boxes use your machine's memory while they run. Stopping them frees it. The messages are gone — that is fine, they were fake. You can start again any time with docker compose up -d.
docker compose downdown— stop the boxes and remove them. (upstarts them;downtakes them down. They are opposites.)
What you should see:
✔ Container kafka-a Removed
✔ Container kafka-b Removed
✔ Container mm2 RemovedHow to tell it worked: all three lines say Removed. The downloaded Kafka image stays on your machine — down removes the boxes, not the image — so the next start is fast and does not download again.
What you can now say, truthfully
"I ran two Kafka clusters on my own machine, made a topic, sent messages with a producer, read them with a consumer, and copied the topic to a second cluster with MirrorMaker 2."
And if you did the extra practice: "I broke the mirror on purpose, read the log, fixed the one wrong line, and watched it catch up by itself."
What this lab does NOT cover
- Real clusters run three or more brokers, not one. The ideas are the same; the setup is bigger. Here each cluster has exactly one broker, on purpose, so you can learn the ideas on one machine.
- MirrorMaker 2 can also copy in the other direction. This lab copies one way only, on purpose.
- Kafka keeps messages for a set time, then deletes them. This lab does not change that setting.
- The Advanced section at the end of this lesson now covers replication factor, acks, consumer groups, lag, auth/TLS, and corrects the "cluster b always has the copy" claim.
Sources
- Apache Kafka docs — https://kafka.apache.org/documentation
- MirrorMaker 2, in the same docs — https://kafka.apache.org/documentation/#georeplication
- The kit's own Best Sites lesson (phase2/best-sites.md) lists the Kafka docs first for Kafka: "free, written by the people who make Kafka".
Nothing was copied from these sources. Every explanation above is written in our own plain words, in the owner's teaching pattern: what it is, why we run it, then the command.
Advanced — Durability, consumer groups, lag, and the mirroring correction
This section is for the reader who already did the lab above. It covers the four things the review of this kit flagged as missing for advanced readers: replication factor and durability, consumer groups and offsets, lag monitoring, and auth/TLS basics — plus a plain-words correction to a claim in this lab. The commands were checked against this lab's own files and the Kafka docs. The durability commands that change settings were not run on this kit's single-broker clusters — read their warnings before you run them.
Advanced 1 — The correction: cluster b does NOT always have the copy
The lab says, in plain words, "if cluster a dies, cluster b still has the copy". That overstates what MirrorMaker 2 does, and the lab's own Step 6 proves it: after cluster a dies, cluster b shows only four orders, and order-105 is missing. Why: MirrorMaker 2 copies asynchronously — a copy machine that reads from a and writes to b in its own time, seconds behind. A message written to a a moment before the crash may never have been copied yet. So the true sentence is: "cluster b has every message MirrorMaker 2 finished copying before a died — and nothing written after that." A copy that lags is not a backup. Also, MirrorMaker 2 copies messages, not your consumer's place: a consumer reading on b starts from where its own group's bookmark says, not from where a's consumer stopped. Bookmarks are next.
Advanced 2 — Replication factor, acks, and durability
What this is: replication factor is how many copies of each message Kafka keeps. Acks (acknowledgements) is how many copies the producer waits for before it calls a write done. Durability is the promise that a written message survives a machine dying. Why they matter together: one setting alone promises nothing. A replication factor of 3 with acks=1 still loses messages when the leader dies before the copies arrive.
This lab creates the topic with one copy:
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 1 --replication-factor 1--replication-factor 1 means one copy. If that one broker dies, the messages are gone. Look at what the topic actually has:
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic ordersWord by word: --describe means "show the details". What you should see: a line naming the topic, then a line per partition with Leader, Replicas, and Isr. Isr means in-sync replicas: the copies that are currently caught up with the leader. On this lab you will see Replicas: 1 and Isr: 1 — one copy, and it is caught up, because there is nothing else.
The three producer settings, in plain words:
acks=0— the producer sends the message and does not wait for any answer. Fastest, and messages can vanish silently.acks=1— the producer waits until the leader has written the message. Safe against the producer crashing, not against the leader dying before the copies arrive.acks=all— the producer waits until every in-sync replica has the message. Slowest, safest. This is the production default.
Try it in this lab. The console producer takes producer settings with --producer-property:
docker exec kafka-a /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders --producer-property acks=allType one line, then press Ctrl+C to stop. On this one-broker lab acks=all behaves exactly like acks=1, because there is only one copy — the setting only matters once replicas exist. That is the lesson: the setting is real, the lab is too small to show its effect.
The fourth setting ties them together: min.insync.replicas is the smallest number of in-sync copies that must say yes before an acks=all write succeeds. Real clusters run replication factor 3 with min.insync.replicas=2: one broker may die and writes still succeed (two copies left), but if two die, writes stop rather than risk losing data. The command that sets it on a topic is real, and it is shown here so you can read it — do NOT run it on this lab:
docker exec kafka-a /opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name orders --alter --add-config min.insync.replicas=2Word by word: kafka-configs.sh changes settings. --entity-type topics --entity-name orders means "the topic called orders". --alter --add-config min.insync.replicas=2 means "change it, setting min.insync.replicas to 2". Why not run it here: this lab has replication factor 1, so 2 in-sync copies can never exist, and every acks=all write would fail. A setting that demands more copies than exist blocks all writes. That is a real production outage shape, learned here for free.
One more setting, because the lab's "does NOT cover" section mentions it: Kafka keeps messages for a set time, then deletes them. The default is log.retention.hours=168 — 168 hours, or 7 days. See the current setting with:
docker exec kafka-a /opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name orders --describeAdvanced 3 — Consumer groups, offsets, and lag
What this is: a consumer group is a team of consumers reading one topic together. Kafka gives each message to one member of the group, so the team shares the work. An offset is a bookmark: the number of the next message a group has not read yet, kept per partition. Lag is how far behind a group is: the newest message number minus the group's bookmark.
Why it matters: lag is the first number to check when someone says "the orders are slow". A growing lag means consumers cannot keep up. A lag of zero means they are caught up.
Try it in this lab. First, read the topic with a named group, so the group exists to inspect:
docker exec kafka-a /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning --group demo-readers --timeout-ms 5000Word by word: --group demo-readers names the group demo-readers. Without it, the console consumer invents a new random group name every run, and you can never find it again. --timeout-ms 5000 stops after 5 seconds of no new messages, as the lab already uses. Now inspect the group:
docker exec kafka-a /opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group demo-readersWord by word: kafka-consumer-groups.sh is the tool for groups. --describe --group demo-readers means "show the details for the group demo-readers". What you should see: one line per partition, with columns GROUP, TOPIC, PARTITION, CURRENT-OFFSET, LOG-END-OFFSET, LAG. Read them as: CURRENT-OFFSET is the group's bookmark. LOG-END-OFFSET is the newest message number. LAG is the difference: newest minus bookmark. After the read above, LAG should be 0 — the group read everything. List all groups with:
docker exec kafka-a /opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --listThree rules that save real incidents:
- Lag is per partition, not per topic. One stuck partition can hide behind a healthy-looking total. Always read the per-partition lines.
- A group's bookmark moves only when the consumer says "I have processed up to here" — that is called committing the offset. If a consumer crashes before committing, it re-reads those messages after restart. Re-reading is normal in Kafka; your consumer must handle the same message twice (the end-to-end lab's worker does this with
ON CONFLICT DO NOTHING— see that lab's Advanced section). - You can move a bookmark by hand with
--reset-offsets. The safe way to learn it: run it WITHOUT--executefirst — it only prints what it would do. With--executeit really moves the bookmark, and messages can be skipped or re-read.
docker exec kafka-a /opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group demo-readers --topic orders --reset-offsets --to-earliestNo --execute, so nothing moves. It prints the plan. That is the safe way to practise a dangerous command.
Advanced 4 — Lag monitoring: what to alert on
What this is: monitoring lag means watching the LAG number over time and shouting when it grows. Why it matters: lag is the earliest warning that a consumer is stuck, slow, or dead — hours before users notice missing orders.
What to alert on: not one number, but a trend. Alert when lag grows steadily for 10 minutes, or passes a limit your team chooses (for example, 1,000 messages). A lag that sits still at a high number means the consumer stopped; a lag that grows means it cannot keep up. Also watch under-replicated partitions: partitions whose in-sync copies are fewer than the replication factor. Any number above zero means data is at risk:
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --under-replicated-partitionsWhat you should see on a healthy lab: nothing, or an empty result. On this one-broker lab the idea is what matters — with one copy, there is nothing to fall behind.
This kit has no lag dashboard. The tools teams use in real work: the kafka-consumer-groups.sh --describe command above (manual, and enough for learning), Burrow (a free lag-watching service), or the Prometheus JMX exporter (Kafka's numbers exported so Prometheus can alert on them — the same Prometheus the portfolio lesson sets up). Do not install any of these for this lab; know their names and what they do.
Advanced 5 — Auth and TLS basics
What this is: auth (authentication) means proving who you are before Kafka lets you in. TLS means scrambling the traffic so nobody in the middle can read it. Why it matters: this lab runs with neither. Look at the lab's own compose file: the listener is PLAINTEXT://:9092. PLAINTEXT means plain text, no scrambling, no login. Anyone who can reach port 9092 can read every message and write new ones.
The real setup, in plain words: Kafka listeners have names, and the name says what protection they use. PLAINTEXT is none. SASL_PLAINTEXT adds a login (SASL is the login system; SCRAM is the usual password method) but still no scrambling. SASL_SSL adds both: a login and scrambled traffic. On top of that, ACLs (access control lists) say which user may read which topic and which may write — so one team's producer cannot read another team's topic.
Setting up SASL and TLS needs certificate files and user accounts this lab does not create, so this section does not give you commands to run here — that would be guessing. What you must carry away: never expose a PLAINTEXT Kafka port beyond your own machine. The lab binds it to 127.0.0.1 only, which is the one protection it has. If you ever see a Kafka port open to the internet with no login, that is an emergency, not a setup.
What you can now say, truthfully — advanced
- "I can explain why replication factor 1 with
acks=1loses messages when the broker dies, and whatacks=allwithmin.insync.replicas=2buys on a three-broker cluster." (Only if you did Advanced 2.) - "I measured consumer lag with
kafka-consumer-groups.sh --describeand can read CURRENT-OFFSET, LOG-END-OFFSET, and LAG." (Only if you did Advanced 3.) - "I know MirrorMaker 2 copies asynchronously, so cluster b only has what was copied before cluster a died — the lab's own Step 6 shows order-105 missing." (Only if you did Advanced 1.)
- "I know this lab's Kafka runs PLAINTEXT with no login, and what SASL_SSL and ACLs add in real work." (Only if you did Advanced 5.)
Quick check — try it yourself
Question: In the terminal, type: docker compose ps — which three containers (small boxes holding programs) show as Up?
Open the practice terminal to test this →
Show answer
You should see kafka-a Up, kafka-b Up, and mm2 Up.