Level 6 / Project 03 - Idempotency Key Builder¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | — |
Focus¶
- stable key generation and dedupe setup
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-6/03-idempotency-key-builder
python project.py --input data/sample_input.txt --output data/output_summary.json
pytest -q
Expected terminal output¶
Expected artifacts¶
data/output_summary.json— dedup results with key counts- Passing tests (
pytest -q→ 7+ passed) - Updated
notes.md
Alter it (required)¶
- Add a
--key-fieldsCLI argument that lets the user choose which fields form the key (instead of hardcoded source + action). - Add a TTL (time-to-live): keys older than N seconds should be considered expired and allow re-processing.
- Add a
list_keysCLI subcommand that prints all stored keys with their timestamps. - Re-run script and tests after each change.
Break it (required)¶
- Submit operations with identical
source+actionbut different other fields — observe that they are treated as duplicates. - Change the separator in
build_keyfrom|to empty string and create a collision withbuild_key("ab", "cd")vsbuild_key("abc", "d"). - Pass an input file with missing
sourceoractionfields.
Fix it (required)¶
- Add validation that required key fields exist before calling
build_key. - Write a test proving the separator prevents accidental collisions.
- Handle the "same key, different payload" case by logging a warning.
Explain it (teach-back)¶
- Why is SHA-256 a good choice for idempotency keys vs. a simple string concat?
- What does
INSERT OR IGNOREdo, and how does it differ fromINSERT OR REPLACE? - Why is the pipe separator important for avoiding hash collisions?
- In what real-world systems would you need idempotency keys?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
- Classes and Objects
- Collections Explained
- Files and Paths
- Functions Explained
- Quiz: Classes and Objects
| ← Prev | Home | Next → |
|---|---|---|