Level 2 / Project 11 - Retry Loop Practice¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 40 minutes
Focus¶
- retry attempts with clear logging
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-2/11-retry-loop-practice
python project.py --operations 10 --failure-rate 0.6 --attempts 5
python project.py --operations 5 --failure-rate 0.9 --attempts 3
pytest -q
Expected terminal output¶
Simulating 10 operations (failure_rate=0.6, max_attempts=5)
Operation 1: OK (attempts: 2)
Operation 2: FAILED (attempts: 5)
...
=== Summary ===
9 passed
Expected artifacts¶
- Retry simulation results on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--jitterflag that adds random variation to delay times. - Add a
--fail-fastmode that stops all operations after the first failure. - Log each retry attempt with a timestamp.
Break it (required) — Core¶
- Set
--failure-rate 1.0— every operation should exhaust all attempts. - Set
--attempts 0— what happens with zero allowed attempts? - Set
--delay -1— negative delay makes no sense.
Fix it (required) — Core¶
- Validate that max_attempts is at least 1.
- Validate that delay is non-negative.
- Add tests for edge-case configurations.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- What is exponential backoff and why is it used?
- Why catch specific exceptions instead of bare
except? - What is a closure and how does
make_countdown_functionuse one? - Where is retry logic essential in real systems (networks, APIs, databases)?
Mastery check¶
You can move on when you can: - implement retry with exponential backoff from memory, - explain why backoff prevents "thundering herd" problems, - describe the difference between flaky and deterministic test helpers, - add jitter to a retry delay calculation.
Related Concepts¶
- Classes and Objects
- Collections Explained
- Decorators Explained
- Errors and Debugging
- Quiz: Classes and Objects
| ← Prev | Home | Next → |
|---|---|---|