Module 9 exercises

Each exercise has a start notebook to work in and a solution notebook to compare with afterwards.

Exercise 1: Fail back to the primary

Goal: move billing and the gateway back to the primary cluster without charging any session twice or missing one. · Time: ~20 min · Starter: code/module-09/exercise-1/start/

The start notebook replays a failover: 15 seconds on the primary, the North site fails, billing and the gateway continue on the DR cluster, and the primary comes back. MirrorMaker 2 copies the sessions written on the DR cluster to the primary as dr.m09e1-sessions. Change failback() so that billing and the gateway end up on the primary with every finished session charged exactly once. Billing on the primary writes to a second ledger, so the check can tell charges made after the failback from earlier ones. Then replace the runbook cell with your runbook for failing back.

You're done when: the notebook prints charged again after failing back: 0, never charged: 0 and all right: True, and your runbook lists the steps in order with the check before each one.

Hints

Hint 1 Run the start version first and look at what it charges again. Where does billing on the primary start reading each of its two topics?
Hint 2 Failing back is planned: stop new writes, let billing on the DR cluster finish, make sure everything it read is on the primary too, then start billing on the primary at a position you set yourself.

Exercise 2: An integration test for the dead-letter path

Goal: write an integration test against a real Kafka, and check that it can fail. · Time: ~20 min · Starter: code/module-09/exercise-2/start/

Billing parks a session event it can't read in charges.dlq, in the same transaction as the charges (module-09/billing.py). Complete test_billing_dlq.py in the start folder. Its setup writes 30 sessions with two broken events among them: one without energy_kwh, one that isn't JSON. Your test runs billing and proves four things:

The notebook runs your test, then runs it again against a billing without a dead-letter path, where it must fail.

You're done when: the notebook prints your test passes: True, it fails against billing without a dead-letter path: True and done: True.

Hints

Hint 1 The integration test of lesson 9.2 already runs `BillingService` against the container and reads committed records; copy its pattern, with `dlq_topic="charges.dlq"`.
Hint 2 Each parked record's `dlq.source.partition` and `dlq.source.offset` headers lead back to a record in `sessions`; read that topic and compare values. For the offsets, compare the group's committed offsets with the end offsets of `sessions`.