Date: 2025-11-25 Commit: 6528e3d Status: Ready for next phase
- File:
oilpriceapi/retry.py - Change: Added 0-30% randomized jitter to exponential backoff
- Impact: Prevents thundering herd during API outages
- Tests: 100% coverage with 12 test cases
Before:
def calculate_wait_time(self, attempt: int) -> float:
return min(2 ** attempt, 60) # Always same wait timeAfter:
def calculate_wait_time(self, attempt: int) -> float:
base_wait = min(2 ** attempt, 60)
if self.jitter:
jitter_amount = random.uniform(0, 0.3 * base_wait)
return base_wait + jitter_amount # Randomized per client
return base_wait- File:
oilpriceapi/async_client.py - Change: Configure httpx.Limits (max 100 concurrent, 20 keepalive)
- Impact: Prevents resource exhaustion under concurrent load
Before:
self._client = httpx.AsyncClient(...) # Unlimited connectionsAfter:
limits = httpx.Limits(
max_connections=self.max_connections, # Default: 100
max_keepalive_connections=self.max_keepalive_connections # Default: 20
)
self._client = httpx.AsyncClient(..., limits=limits)Command: pytest tests/unit/test_retry.py -v
Results:
- ✅ 12/12 tests pass
- ✅ 100% coverage on retry.py
- ✅ Jitter variance verified (50+ unique values in 100 runs)
- ✅ Exponential backoff verified (1s, 2s, 4s, 8s...)
- ✅ 60-second cap verified with jitter
Before Phase 1: 64.48% After Phase 1: (Run tests to measure)
New Tests Added:
test_default_configuration()test_custom_configuration()test_should_retry_on_retryable_status()test_should_not_retry_on_non_retryable_status()test_should_not_retry_after_max_attempts()test_should_retry_on_exception()test_exponential_backoff_without_jitter()test_exponential_backoff_with_jitter()test_jitter_prevents_synchronized_retries()test_jitter_maintains_cap_at_60_seconds()test_log_retry_formats_message()test_log_retry_async_client()
Timeline: This weekend Effort: 2 hours to update post
Post will claim:
- ✅ Exponential backoff with jitter (VERIFIED)
- ✅ Connection pool limits (VERIFIED)
- ✅ Comprehensive exception handling (EXISTS)
- ✅ Async/await support (EXISTS)
- ✅ Type hints (EXISTS)
- ❌
Caching with fallback(IN ROADMAP) - ❌
Circuit breaker(IN ROADMAP) - ❌
Data validation(IN ROADMAP)
Honest Roadmap Section:
## Roadmap
Building production-ready features based on community feedback:
**Phase 1 (Complete):**
- [x] Retry jitter to prevent thundering herd
- [x] Connection pool limits
- [x] Comprehensive test suite
**Phase 2 (Planned - Q1 2025):**
- [ ] Response caching with fallback (Issue #4)
- [ ] Circuit breaker pattern (Issue #5)
- [ ] Test coverage to 84%+ (Issue #11)
**Phase 3 (Future):**
- [ ] Client-side data validation (Issue #6)
- [ ] OpenTelemetry integration (Issue #7)
Contributions welcome!Timeline: 3 more weeks Effort: 120 hours
Deliverables:
- Caching layer (3 days)
- Circuit breaker (2 days)
- Comprehensive testing (3 days)
- Documentation (1 day)
- Test coverage to 84%+
Then: Post perfect Reddit post matching all claims
Post Now (Option A) for these reasons:
- Trust Building: Honest post builds more credibility than delayed perfect post
- Feedback Loop: Learn what users actually want before building Phase 2
- Quick Wins: Phase 1 improvements are real and valuable
- Low Risk: No false claims, clear roadmap
- Time to Market: 3 weeks is a long time in the Python ecosystem
The Sr. QA Engineer says:
"Ship what you have. It's solid. Get feedback. Iterate. That's how you build products people want, not products you think they need."
oilpriceapi/retry.py +94 lines (NEW FILE)
oilpriceapi/async_client.py +47, -16 lines
oilpriceapi/client.py (updated to use RetryStrategy)
tests/unit/test_retry.py +177 lines (NEW FILE)
Total: +364 lines, -31 lines
- Without jitter: All clients retry at same time → API overload
- With jitter: Clients retry spread across 30% window → Smooth recovery
- Before: Unlimited connections → Resource exhaustion possible
- After: Max 100 concurrent → Predictable resource usage
- ✅ Phase 1 complete (DONE)
- Update Reddit post (READY_TO_SUBMIT.md)
- Post to r/Python (Tuesday-Thursday morning)
- Monitor feedback
- Decide Phase 2 based on user demand
- ✅ Phase 1 complete (DONE)
- Implement caching (see IMPLEMENTATION_PLAN_PHASES.md)
- Implement circuit breaker
- Improve test coverage
- Post perfect Reddit post
You need to decide:
- Option A: Post honest version this weekend (2 hours work)
- Option B: Continue Phase 2-3 (3-4 weeks work)
Both are valid. Option A is lower risk and faster feedback.
To continue Phase 2:
# See detailed implementation plan
cat IMPLEMENTATION_PLAN_PHASES.md
# Start with caching layer
mkdir -p oilpriceapi/cache
# Implement as detailed in planTo post now:
# Update Reddit post
# Remove cache/circuit breaker/validation claims
# Add honest roadmap
# Post to r/Python Tuesday-Thursday morningPhase 1 Status: ✅ COMPLETE Next Phase: Your decision Recommendation: Post now, iterate based on feedback