Level 5 / Project 10 - API Polling Simulator¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Quick Recall: This project uses rule-based scoring to decide when to retry or back off. Before starting, make sure you can: write a function that evaluates multiple conditions and returns a score or category based on thresholds (Level 1, Project 02 - Password Strength Checker).
Estimated time: 80 minutes
Focus¶
- poll cycles, retries, and delays
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-5/10-api-polling-simulator
python project.py --max-polls 10 --output data/poll_results.json
pytest -q
Expected terminal output¶
Expected artifacts¶
data/poll_results.json- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--timeoutflag that stops polling after N seconds regardless of max polls. - Track and report the average response time per successful poll.
- Add a
--fail-rateparameter to control the MockAPI's simulated failure percentage. - Re-run script and tests.
Break it (required) — Core¶
- Set
--max-polls 0and observe the behavior. - Configure the MockAPI to always return rate-limit errors and watch backoff grow indefinitely.
- Capture the first failing test or visible bad output.
Fix it (required) — Core¶
- Validate that max_polls is at least 1.
- Cap the maximum backoff delay so it does not grow unbounded.
- Add tests for zero-polls and capped backoff.
- Re-run until output and tests are deterministic.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- How does
poll_with_backoffincrease the delay after each rate-limit response? - What is the purpose of the
MockAPIclass in testing? - Why is exponential backoff better than fixed-interval polling?
- Where do you see polling with backoff in production (AWS SDK, GitHub API, payment webhooks)?
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¶
| ← Prev | Home | Next → |
|---|---|---|