Brief
Explain and simulate a per-partition Kafka restart that finds OPEN-18 without repeating OPEN-17's effect.
The service screens restart. Voss claims the second command was lost during the stop; Imani fears a naive replay might open the same door twice. Mara gives you the group's two bookmarks and four practice records. Prepare a replay plan before the fictional meeting. No real system is touched, and this exercise has no timer.
Your mission
- List messages in each partition with offsets.
- List positions read after restart.
- Name new commands applied when OPEN-17 is already durably recorded.
- Explain why an offset alone does not ensure a unique effect and when retention prevents replay.
How to check your work
- P0 has 40,41,42; P1 has 12.
- Replayed positions 0/41, 0/42, 1/12.
- Only OPEN-18 is new; OPEN-17 is not reapplied.
- Offset and effect differ; an expired record cannot be reread from that point.
Course example
records = [
{"partition": 0, "offset": 40, "event_id": "E1", "command_id": "OPEN-17"},
{"partition": 0, "offset": 41, "event_id": "E1", "command_id": "OPEN-17"},
{"partition": 0, "offset": 42, "event_id": "E2", "command_id": "OPEN-18"},
{"partition": 1, "offset": 12, "event_id": "E3", "command_id": "OPEN-17"},
]
next_offset = {0: 41, 1: 12}
already_applied = {"OPEN-17"}
replayed = [
record for record in records
if record["offset"] >= next_offset[record["partition"]]
]
new_effects = []
for record in sorted(replayed, key=lambda item: (item["partition"], item["offset"])):
if record["command_id"] not in already_applied:
already_applied.add(record["command_id"])
new_effects.append(record["command_id"])
print("replayed_positions", [(r["partition"], r["offset"]) for r in replayed])
print("new_effects", new_effects)
print("all_commands", sorted(already_applied))