Module 2 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: A key for driver notifications
Goal: choose a record key from an ordering requirement, and prove it works. · Time: ~10 min · Starter: code/module-02/exercise-1/start/
The driver app sends four notifications per charging session: charging started, 80% reached,
charging finished and receipt ready. A driver who sees "receipt ready" before "charging started"
calls support. The start notebook generates 1,200 notifications for 299 drivers and writes them to
the 6-partition topic m02e1-notifications with the key your function key_for(note) returns.
Complete key_for(), run the notebook, and in a markdown cell explain why you didn't choose the
session id or the charger id.
You're done when: the check cell prints drivers who saw notifications out of order: 0 of 299
and the busiest partition holds at most twice as many records as the quietest.
Hints
Hint 1
Ask "whose notifications must stay in order?". The answer is the key.Hint 2
A driver who charges twice in the evening has two sessions. Their notifications must still be in order across both sessions.Exercise 2: Tune the replay producer
Goal: pick batching and compression settings from measurements. · Time: ~15 min · Starter: code/module-02/exercise-2/start/
After an outage the gateway replays its buffered readings: the same 100,000-reading backlog as in
lesson 2.3. The start notebook measures the producer defaults first, then runs each compression codec
once. Choose settings for my_settings that, compared with the defaults:
- are at least as fast (within 5%),
- store at most half the bytes,
- keep p99 latency under 250 ms,
- and stay safe:
acks=alland idempotence on.
Then write down which codec you'd run in production and why, using your own numbers.
You're done when: all three checks print True, and your note names the codec and the
trade-off you accepted.
Hints