Module 1 exercises
Start the lab first (docker compose up -d --wait in the code/ folder). Each exercise has a
start notebook to work in and a solution notebook to compare with afterwards.
Exercise 1: Answer a dispute
Goal: read one charger's records for a time window without reading a whole topic. · Time: ~10 min · Starter: code/module-01/exercise-1/start/
A fleet driver says charger BL-C08-02 delivered almost nothing between 18:00 and 18:10
yesterday. The start notebook writes yesterday evening's telemetry into m01e1-telemetry
(3 partitions, keyed by charger id, each record stamped with its event time).
Collect BL-C08-02's meter readings stamped from 18:00 up to (not including) 18:10 into a list
called readings. Don't start reading at offset 0: use a time search. Stop reading once you pass
18:10.
You're done when: the check cell prints BL-C08-02: 60 readings between 18:00 and 18:10,
11.23 kWh delivered and matches the gateway's own records: True.
Hints
Hint 1
You don't know BL-C08-02's partition, but a time search on all three partitions costs one request. Pass three `TopicPartition(TOPIC, p, from_ms)` objects to `offsets_for_times`.Hint 2
`assign()` accepts the list that `offsets_for_times` returns. While reading, `msg.timestamp()[1]` is the record's timestamp in milliseconds: stop a partition when it reaches `to_ms`.Exercise 2: A cluster health report
Goal: read partition leaders, replicas and ISR from code, and watch a broker leave and rejoin. · Time: ~15 min · Starter: code/module-01/exercise-2/start/
Write health_report(topic). It prints one row per broker: whether the broker is online, how
many partitions it leads, how many of its replicas are in sync and how many are out of sync. Then
it lists the under-replicated partitions and returns how many there are. The notebook then runs
your report while it stops and restarts kafka-3.
Finally, in a markdown cell, write the bootstrap.servers value you'd give the charger gateway
running in Docker next to the brokers, and the one for a notebook on your Mac, and say why they
differ.
You're done when: the report shows no under-replicated partitions before the stop, all 6
under-replicated with broker 3 OFFLINE during it, none after the restart, and your two bootstrap
lists use the right listener for each place.
Hints