Module 7 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: Charge and receipt in one transaction
Goal: make a second output part of the same exactly-once transaction. · Time: ~15 min · Starter: code/module-07/exercise-1/start/
Billing now also sends every driver a receipt, to m07e1-receipts. The start script
billing_with_receipts.py writes charges and offsets in one transaction, as in lesson 7.1. But the
receipts go out through the notification team's own producer, outside the transaction. The notebook
crashes the service after 150 charges, runs it again, and reads both topics with read_committed.
Change the script so that every charge comes with exactly one receipt, also after the crash. Then, in a markdown cell, explain where the extra receipts came from.
You're done when: the notebook prints exactly one receipt per charge: True, with 400 charges and
400 receipts.
Hints
Hint 1
Which producer's records are covered by `commit_transaction()`, and which aren't?Hint 2
One transaction can write to several topics, as long as one transactional producer writes them all.Exercise 2: Peak kW per site per window
Goal: write a two-level windowed aggregation. · Time: ~20 min · Starter: code/module-07/exercise-2/start/
Besides energy, the grid operator wants each site's peak load per 5-minute window: the highest
total power its chargers drew at the same moment. Every charger sends one reading every 10 seconds,
so "the same moment" is a 10-second slot. The site's load in a slot is the sum of power_kw of its
readings in that slot, and the peak is the highest slot load in the window.
The start notebook writes one hour of readings to m07e2-telemetry, reads them back in order and
calls your add(state, reading) for each. Then it calls peak_kw(state) and compares the result
with values computed from the scenario's data. Use event time (the reading's ts). Then, in a
markdown cell, say how much state your version keeps for a whole day, and how a long-running service
would keep it small.
You're done when: the notebook prints all right: True (326 windows, and site-N03's peaks as
expected), and your note answers the state question.
Hints