Level 8 / Project 03 - Pagination Stress Lab¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | — |
Focus¶
- Offset-based and cursor-based pagination strategies
- Edge case handling: empty pages, beyond-range, partial last page
- Stress testing with multiple page sizes
- Invariant verification (no duplicates, no missing items)
Why this project exists¶
Pagination bugs are among the most common issues in web APIs. Off-by-one errors, empty last pages, and item drift during inserts all cause real production incidents. This lab builds both offset and cursor paginators, then stress-tests them to verify correctness.
Run (copy/paste)¶
cd <repo-root>/projects/level-8/03-pagination-stress-lab
python project.py --items 47 --page-sizes 1 5 10 25 100
pytest -q
Expected terminal output¶
{
"data_size": 47,
"page_sizes_tested": [1, 5, 10, 25, 100],
"verification": [{"page_size": 1, "matches_total": true}, ...],
...
}
7 passed
Alter it (required)¶
Extend this project in a meaningful way — add a feature that addresses a real use case.
Break it (required)¶
Introduce a subtle bug and see if your tests catch it. If they don't, write a test that would.
Fix it (required)¶
Review your code critically — is there a design pattern that would improve it?
Explain it (teach-back)¶
Could you explain the architectural trade-offs to a colleague?
Mastery check¶
You can move on when you can: - explain why math.ceil is needed for total_pages, - describe the tradeoff between offset and cursor pagination, - write a stress test that catches off-by-one errors, - explain why the last page often has fewer items than page_size.
Mastery Check¶
- Can you explain the architectural trade-offs in your solution?
- Could you refactor this for a completely different use case?
- Can you identify at least two alternative approaches and explain why you chose yours?
- Could you debug this without print statements, using only breakpoint()?
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|