Open lesson

Mission: bookmarks after the failure

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

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

  1. List messages in each partition with offsets.
  2. List positions read after restart.
  3. Name new commands applied when OPEN-17 is already durably recorded.
  4. 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))

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with # are task reminders. Python ignores them. Write your code beneath them.

Python console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.py

Current editor source. Inspection shows your current edits.

# 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.

exemple.py

Declarative lesson asset; this is not a file created in the Python filesystem.

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))